简体   繁体   中英

How to extract a value from JSON in Presto?

{"xyz":{"aaabc":"80.00","ccccd":null,"npccc":"0.00","txnid":"pca","diccsc":"0.00"}}

I have to extract xyz where xyz is dynamic variable ( in some case it maybe xyz in other it may be abc or anything )

Assuming your data is a varchar , you can

  • convert to json
  • cast to map(varchar, json)
  • extract entries from a map with map_entries
  • get the first one
SELECT map_entries(CAST(CAST(my_column AS json) AS map(varchar, json))[1]
FROM ...

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