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

Enhanced support for updating json using jsonpath #35

Open
karlkfi opened this issue Sep 17, 2021 · 2 comments · May be fixed by #48
Open

Enhanced support for updating json using jsonpath #35

karlkfi opened this issue Sep 17, 2021 · 2 comments · May be fixed by #48

Comments

@karlkfi
Copy link

karlkfi commented Sep 17, 2021

This is an interesitng project! It seems like it's the only jsonpath library that supports mutation and not just retrieval. That said, the mutation API/behavior could be improved.

I'd like to be able to mutate json using jsonpath. This leads to two asks:

  1. I'd also like to be able to pass an interface{} to a Node.Set function and have it handle conversion to the right type, erroring if the type is invalid. I think this just means exporting the internal update method: https://github.com/spyzhov/ajson/blob/master/node_mutations.go#L147
  2. If the node exists, ajson makes mutation easy by supporting Set fields on Node. However, if there's no match, because the node or it's parents don't exist, I'd like to be able to easily auto-generate the node and any parent maps & arrays to match the jsonpath expression.
@spyzhov
Copy link
Owner

spyzhov commented Sep 17, 2021

Thanks a lot for your comment, it's really nice to hear.

About your suggestions:

  1. Yes, you're right. It's quite a small and helpful fix, I'll do it in the nearest future.
  2. I thought about it. And you know, at the very beginning I thought that it is not impossible, because you can use something like $..leaf.*.new_field. But if I'd add some limitations, like: "only direct names (or 0 to add the first item in the array) after the leaf element", then it would be enough to generate a new subtree. Like $..leaf[0].new.element["0"]
    So, I suppose, I can implement it with some limitations. But not sure about the due date.

spyzhov added a commit that referenced this issue Nov 5, 2021
spyzhov added a commit that referenced this issue Nov 5, 2021
spyzhov added a commit that referenced this issue Nov 6, 2021
spyzhov added a commit that referenced this issue Nov 6, 2021
spyzhov added a commit that referenced this issue Nov 6, 2021
* Implemented `node.Set` and `node.SetNode` methods

* Added `go1.17.x` version to test

* Updated release version

* Added default results for `(*Node)(nil)` methods
@spyzhov
Copy link
Owner

spyzhov commented Nov 6, 2021

I implemented methods Set and SetNode int the v0.6.0.

I prefer to implement the second part of the request in the v1.0.0 of the library, as soon as it causes backward-incompatible changes. The next I'm going to develop will be exactly v1.0.0.

@spyzhov spyzhov linked a pull request Feb 17, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants