I have a big JSON data in one column called response_return
in a Postgres DB, with a response like:
{
"customer_payment":{
"OrderId":"123456789",
"Customer":{
"Full_name":"Francis"
},
"Payment":{
"AuthorizationCode":"9874565",
"Recurrent":false,
"Authenticate":false,
...
}
}
}
I tried to use Postgres functions like ->
,->>
,#>
or @>
to walk through headers to achieve AuthorizationCode for a query.
When I use ->
in customer_payment in a SELECT, returns all after them. If I try with OrderId, it's returned NULL.
The alternatives and sources:
Using The JSON Datatype In PostgreSQL
Operator ->
- Allows you to select an element based on its name.
- Allows you to select an element within an array based on its index.
- Can be used sequentially: ::json->'elementL'->'subelementM'->…->'subsubsubelementN'.
- Return type is json and the result cannot be used with functions and operators that require a string-based datatype. But the result can be used with operators and functions that require a json datatype.
Query for element of array in JSON column
This is not helpful because I don't want filter and do not believe that need to transform to array.