question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Recommendation for updating a nested value inside a JSON field?

See original GitHub issue

I’d like to update a JSON field by changing one of it’s nested fields.

In mongo, you do this like (http://docs.mongodb.org/manual/reference/operator/update/set/#up._S_set):

instance.update({
  json_field: {
    "$set": {
        "nested_field": "value"
     }
   }
})

Is there anything like that with Sequelize/Postgres? Right now all I can do is read/write the entire JSON field, it doesn’t seem like I can do deep updates to parts of it.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

11reactions
dylanlingelbachcommented, Feb 28, 2018

@tudor33sud What I am doing is something like:

Table.update(
{
  output: Sequelize.literal(`output || '["${JSON.stringify(obj)"]'`)
},
{
  where: { id }
}

Where obj is the object you are trying to append.

This will do an atomic append to the array.

11reactions
felixfbeckercommented, Nov 7, 2016

This issue is old, instance.set() supports nested field updates through dot-syntax. It is an atomic operation on database level.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update a nested value from a Json field - mysql - Stack Overflow
You can create an endpoint that returns the collected data as a JSON document, even if the rows are stored in a normalized...
Read more >
Manipulating Nested JSON Values in Java Using the org.json ...
First, we'll need to parse our way into the nested value. The JSON Pointer format provides an intuitive way to reference the nested...
Read more >
how to update specific nested json object? : GameSparks
i have that data configuration in my playerData. Now i want to update only the weaponInfo part. for say new weaponInfo will be...
Read more >
Update nested json array fileds - Couchbase Forums
Hi, Please share your thought on how to update on below field “UserList”: ... deptEmpCount & deptId are inside userDept object?how to update...
Read more >
Updating a nested JSON object with data from a related table…
The JSON structure is arbitrarily nested, I can access objects and fields within the JSON with WITH RECURSIVE , along with some use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found