How do i retrieve both the key and the value from a json object?

Matthew

I am trying to retrieve both parts of a JSON object through a stored procedure, for example from {bob:ben, 3:sue, James:cat} I want to get each part of the pair separately using sql. So it would be like this

col1 | col2
bob  | ben
3    | sue
James| cat

How do i do this?

Paplusc

This is easy to achieve by using some of these functions JSON_KEYS, JSON_EXTRACT and JSON_CONCAT.

For example, you could create table iterating this select:

set @json = '{"bob:ben", "3":"sue", "James":"cat"}';
set @indx = 0;
set @keys = JSON_KEYS(@json);
select JSON_EXTRACT(@keys, CONCAT("$[", @indx, "]")) as colum1, 
        JSON_EXTRACT(@json,CONCAT("$.", JSON_EXTRACT(@keys, CONCAT("$[", @indx, "]")))) as colum2;

For further information you have all the JSON mariadb function in this link:

MARIADB JSON FUNCTIONS

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I get a specific key value from JSON object

How to retrieve whole JSON object with key value?

How to retrieve a value given a key in a json object?

How to retrieve key if passed in value is a json object?

In a JSON object, how do I retrieve values of objects within a JSON object without knowing the key?

How do I remove an element from a JSON object by key reference?

How to retrieve data from firebase based on some key's value which is in nested json object

How do I get a separate key and value from the resulting json?

How do i iterate JSON Map and retrieve key-value results in flutter Dart

How do I retrieve the public key from a SSH private key?

How to retrieve a value in a json object in sqlite when the key is an empty string?

how can I retrieve individual values from a multi value key in Swift 4/json dictionary?

How to retrieve value of key from an object inside an array

How do I print value from hashmap json object

How do I iterate through items in a json object and retrieve a specific value in C#?

How do I replace a value of a key from a returned JSON object after calling an API using requests.get?

How to retrieve the key from an array of values of a JSON object?

How do I retrieve JavaScriptObject key/value in AbstractPresenterModule in GWTP?

How do I retrieve a value in the IMemoryCache by the key provided on the API call

How do I get information from one json object with the key of another json object?

How do I retrieve a value from an object using users' inputs? (Angularjs)

How to retrieve value based on Key from JSON string in PosgresSql

xidel: how to retrieve value from JSON key containing dots(.)?

xidel: how to retrieve value from JSON key containing dots(.)?

How do i parse json key value pairs inside a json object using volley andorid

How do I a retrieve specific value from JSON output in Python 2.7?

How to retrieve object value from database stored as json

How do I delete a JSON Object key from the D JSON type?

How do I get the key and it's object from a JSON file in c# using JSON.net?