0

I have the data stored in a table named 'userfields' the below format in one of the columns named 'params' in Postgres SQL. I want to select two json objects and the output should be in the same format

{
        "default": {
                  "model": "core.location",
                  "pk": 119
                    },
        "field1": {
                  "name": "Vista Community Clinic- The Gary Center, S. Harbour Blvd",
                  "full_address": "201 S. Harbor Boulevard, \nLa Habra, CA 90631"
                    }
       "fields2": {
                  "name": "xyz- The Gary Center, S. Harbour Blvd",
                  "full_address": "abc, \nLa Habra, CA 90631"
                   }
}

I have tried and achieved for one json object which will return for example default The query I have used is

select json_extract_path(params::json,'default') as selectedparams from userfields. 

I am not able to select two json objects like default and feild1

The output I have got is

{
                  "model": "core.location",
                  "pk": 119
}

The output I want is I want to get default and field1 as the nested JSON by using PostgreSQL13 query like below

Desired Result:

{
        "default": {
                  "model": "core.location",
                  "pk": 119
                    },
        "field1": {
                  "name": "Vista Community Clinic- The Gary Center, S. Harbour Blvd",
                  "full_address": "201 S. Harbor Boulevard, \nLa Habra, CA 90631"
                    }

}

0 Answers0