Azure SQL - Handling JSON column in the table

Mohan Kumar R S 41 Reputation points
2020-08-05T10:24:59.547+00:00

Hi,

I want to convert table content which contain json value data in one of the column in Azure SQL server. Like below,

Country State Json_value
US Alabama {"name":"John","surname":"Doe","age":45}
Canada Toronto {"name":"Mark","surname":"Bagwell","age":35}

I need to convert as below in the query itself.

Country State name surname age
US Alabama John Doe 45
Canada Toronto Mark Bagwell 35

Is this can be achieved in SQL server query using json function. kindly help me in resolving this.

Azure SQL Database
0 comments No comments

Answer accepted by question author

Anurag Sharma 17,636 Reputation points
2020-08-05T12:11:46.367+00:00

Hi @Mohan Kumar R S , thanks for reaching out to us. we are glad to assist you here. Instead of using 'openjson' function please try below sql query to achieve the desired result:

select country, state, JSON_VALUE(jsonvalue,'$.name') as firstname,JSON_VALUE(jsonvalue,'$.surname') as surname, JSON_VALUE(jsonvalue,'$.age') as age from YourTableName;

Please note that the json properties are case sensitive, so use accordingly.

----------

If an Answer is helpful, please “Accept Answer” or Up-Vote for the same which might be beneficial to other community members reading this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.