简体   繁体   中英

How to get a JSON property value using PostgreSQL

I have a table named appsettings with columns value and key

key column = supported-api-client

in value column i have json like this

{
    "DEV": [
        { 
            "OS": "android", 
            "Version": "28",
        },
        { 
            "OS": "ios", 
            "Version": "1.0.0.1", 
        }
    ] 
}

how do i take these two from that "OS": "android", "Version": "28". any posibilities?

I could reproduce it in postgres 9.4: https://www.db-fiddle.com/f/4jyoMCicNSZpjMt4jFYoz5/4278

SELECT value -> 'DEV' ->> 0
FROM appsettings
WHERE key = 'supported-api-key';

//output
{ "OS": "android", "Version": "28" }

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