Skip to content
Advertisement

Extract nested data in JSON variable in SQL

I need some help extracting the data I need out of a JSON variable in SQL:

JSON Tree

I need to get management_account_id, Month and cost_to_client/details in a table, the problem I am facing is that the month is higher up on the hierarchy than the details section, so I’m going into each individual month to access the details object, below is the code I have:

This is what I’m getting:

Data Snippet

What I want instead is the below which has all the months in it:

Output

JSON in text below:

Advertisement

Answer

If I understand you correctly and you want to avoid explicit columns definitions for the $."cost_to_client" part of the input JSON, the following statement is an option:

Result:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement