Skip to content

JSONPath: Replacing result nodes in data? #94

Answered by ohler55
kabukky asked this question in Q&A
Discussion options

You must be logged in to vote

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}
  ]
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@kabukky
Comment options

Answer selected by ohler55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants