Here is my JSON field value. which is stored in the PostgreSQL table. I want to search and update the specific user_name in the user key
{
"user": [
{
"user_name": "Devang",
"user_weight": 0.7676846955248864
},
{
"user_name": "Meet",
"user_weight": 0.07447325861051013
},
{
"user_name": "L.b.vasoya",
"user_weight": 0.056163873153859706
}
],
"address": [
{
"address_name": "India"
}
]
}
whose name is Devang
to Dev using Django JSONField
for example
"user": [
{
"user_name": "Dev",
"user_weight": 0.7676846955248864
},
....
I have tried the RAWQuery for the find. This is the query.
select json_field->user from user_table where json_field @> '{"user": [{"user_name": "Devang"}]}';
It will return like this
{
"user_name": "Devang",
"user_weight": 0.7676846955248864
},
{
"user_name": "Meet",
"user_weight": 0.07447325861051013
},
{
"user_name": "L.b.vasoya",
"user_weight": 0.056163873153859706
}
]
I have also tried JSON_SET to update the user_name but JSON_SET only accepts. It will update the upper level, not a nesting level