-
Hi, this library seems pretty powerful. I'd like to query data from a JSON object via a JSONPath expression, alter the found fields in-place, and write it all back into a JSON object. E. g.:
This is just an example to hopefully illustrate what I want to do. I'm not sure if Nodes are the right way to go about it. Do you have a pointer for me on how to go about this? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It's actually much simpler than you think. I'll provide something this evening after work. |
Beta Was this translation helpful? Give feedback.
-
Keeping the imports and vars as they are just change main() to: func main() {
x := jp.MustParseString("a[?(@.x > 1)].y")
x.MustSet(input, newData)
fmt.Println(pretty.JSON(input))
} outputs: {
"a": [
{"x": 1, "y": 2, "z": 3},
{"x": 2, "y": {"foo": "bar"}, "z": 6}
]
} |
Beta Was this translation helpful? Give feedback.
Keeping the imports and vars as they are just change main() to:
outputs: