I'm trying to extract the values of a nested array inside JSON in SQL Server but not sure how. I know how to extract JSON items and also how to extract arrays but haven't been able to get the nested array out values. I found one example that supposedly shows how to do this but haven't been able to get it to work.
Here's an example: The following JSON falls under a field called json_data. There is an array under 'order', called 'line_items'. Each item in 'line_items' has multiple fields: 'quantity', 'name', 'total_money', etc.
Extracting the top level variables: 'order', 'id' is easy. But not sure how to go about extracting all the variables under the array 'line_items': specifically, 'quantity', 'name', 'total_money'. I would be grateful for any help. Many thanks!
{'order': {'location_id': 'NYC',
'id': '123',
'source': {'name': 'Kurtz'},
'line_items': [{'quantity': '1',
'name': 'Item1',
'note': 'No notes',
'base_price_money': {'amount': 1000, 'currency': 'USD'},
'total_discount_money': {'amount': 0, 'currency': 'USD'},
'total_money': {'amount': 1000, 'currency': 'USD'}},
{'quantity': '1',
'name': 'Item2',
'note': '',
'base_price_money': {'amount': 400, 'currency': 'USD'},
'gross_sales_money': {'amount': 400, 'currency': 'USD'},
'total_tax_money': {'amount': 0, 'currency': 'USD'},
'total_discount_money': {'amount': 0, 'currency': 'USD'},
'total_money': {'amount': 400, 'currency': 'USD'}}],
'total_money': {'amount': 1400, 'currency': 'USD'},
'total_tax_money': {'amount': 0, 'currency': 'USD'},
'total_discount_money': {'amount': 0, 'currency': 'USD'}},
'location': {'name': 'Breakfast Club',
'address': 'Buena Vista road',
'phone': '555-555-5155'}}