2

I have two JSON objects, original and current.

The original object was created by reading a configuration file, it have a certain specific keys.

The current object was created as a copy of original, then there are keys added to current, as well as updates to other keys from original.

Now I want to copy back from current to original, but only the keys that exists in original. In other words, I don't want the new keys that was added to current.

For example, lets say original is:

{
    "foo": "hello"
}

And current is:

{
    "foo": "world",
    "bar": "some other stuff"
}

After updating original only the "foo" key should have been updated:

{
    "foo": "world"
}

The "bar" key is not copied.

Using the nlohmann-json library, is there a simple way to solve this? Or do I have to iterate over original and explicitly copy those keys from current?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621

0 Answers0