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

Q: Is there a way to set a new value if match the node name #504

Open
GitHubForTroy opened this issue Nov 19, 2018 · 3 comments
Open

Q: Is there a way to set a new value if match the node name #504

GitHubForTroy opened this issue Nov 19, 2018 · 3 comments

Comments

@GitHubForTroy
Copy link

No description provided.

@GitHubForTroy
Copy link
Author

ex : {
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
}
==>
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-****-3",
"price": 8.99
}
if i match "isbn" node

@hf-kklein
Copy link

Yes, there is. This example replaces all nodes named "isbn" with "0-****-3".

DocumentContext dc = JsonPath.parse("insert your json string here")
dc.put("$..isbn", "0-****-3");

If you'd like to replace only some nodes depending on their value you could use e.g. regular expressions inside the path:

$..[?(@.isbn=~/0-\d{3}-\d{5}-3/)].isbn

@akanshSirohi
Copy link

@GitHubForTroy @hf-kklein Can you please check my issue..??
#982 (comment)

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

3 participants