Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.set() method should add the key value if its not present #982

Open
akanshSirohi opened this issue Jan 15, 2024 · 1 comment
Open

.set() method should add the key value if its not present #982

akanshSirohi opened this issue Jan 15, 2024 · 1 comment

Comments

@akanshSirohi
Copy link

akanshSirohi commented Jan 15, 2024

I have this JSON with me

[
    {
      "msg": "hello",
      "_uuid": "1483f2e6-1241-4e84-9fbf-503ce5ea64df"
    },
    {
      "msg": "hello",
      "child": {
        "timestamp": "any_timestamp"
      },
      "_uuid": "dbe96d86-4542-4bbd-b64e-f31d69fa735b"
    }
]

I am executing this code to update the timestamp value

DocumentContext collections_doc = JsonPath.parse(json_data).set("$[?(@.msg == 'hi')].child.timestamp","new_timestamp");

Its just updating the first child.timestamp, is there any solution so that if object don't have any key, then it will be created.

@akanshSirohi
Copy link
Author

@kallestenflo Any updates on this issue, mentioning you here because this might be the important one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant