简体   繁体   中英

how to extract nested json using sqlite json-extract

How could I extract nested json using sqlite json-extract or other sqlite json command ?

Here I'd like to extract given_id

"invoices": [{

........


    "items": [{


    "given_id": "TBC0003B",


    ...


        }


    ]

   }

]

Thanks.

In SQLite you can use json_extract() as follows:

select json_extract(my_json_col, '$.invoices[0].items[0].given_id') my_given_id from mytable

This gives you the given_id attribute of the first element of the items array under first element of the invoices array.

Demo on DB Fiddle :

with mytable as (select '{
    "invoices": [{
        "items": [{ "given_id": "TBC0003B" }] 
    }]
}' my_json_col)
select json_extract(my_json_col, '$.invoices[0].items[0].given_id') my_given_id from mytable
| my_given_id |
| :---------- |
| TBC0003B    |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM