You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off, many thanks for a fantastic library! It's made my life a lot easier and I really appreciate it.
I'm currently using ojg/jp in a CLI tool that (among other things) allows users to modify JSON and YAML files via JSON path expressions. In both cases I'm unmarshalling the files to map[string]any and passing them into jp.Expr.Modify().
One thing I'd like to add is the ability to maintain comments, whitespace, and key ordering when updating YAML files. The YAML lib I'm using supports this when unmarshalling into a yaml.Node, so I've been looking into using that instead of an untyped map.
I noticed the recent addition of the jp.Keyed and jp.Indexed interfaces, and I was thinking about creating a wrapper around yaml.Node that implemented those interfaces. This seems like it would do what I want.
Unfortunately it doesn't look like the jp.Expr.Modify() method supports those new interfaces. That or perhaps I'm invoking it incorrectly 🤷. Here's what I've tried:
I expected the z keys in the data maps to be set to 999. Works as expected when removing the Node wrappers. Also works when using jp.Expr.Set().
I didn't see any references to Indexed or Keyed in https://github.com/ohler55/ojg/blob/develop/jp/modify.go, so I'm thinking that Modify just does't currently support them. I would love to help out and add that myself, but honestly that code is a bit beyond me 😞. Is there any chance you'd be interested in doing so?
The text was updated successfully, but these errors were encountered:
My apologies that it has taken this long for me to get to this. I've started a branch called modify-keyed-indexed that has the start of the updates. All have been implemented but minimally tested if you want to try it out as I add the tests.
Hello!
First off, many thanks for a fantastic library! It's made my life a lot easier and I really appreciate it.
I'm currently using
ojg/jp
in a CLI tool that (among other things) allows users to modify JSON and YAML files via JSON path expressions. In both cases I'm unmarshalling the files tomap[string]any
and passing them intojp.Expr.Modify()
.One thing I'd like to add is the ability to maintain comments, whitespace, and key ordering when updating YAML files. The YAML lib I'm using supports this when unmarshalling into a yaml.Node, so I've been looking into using that instead of an untyped map.
I noticed the recent addition of the
jp.Keyed
andjp.Indexed
interfaces, and I was thinking about creating a wrapper aroundyaml.Node
that implemented those interfaces. This seems like it would do what I want.Unfortunately it doesn't look like the
jp.Expr.Modify()
method supports those new interfaces. That or perhaps I'm invoking it incorrectly 🤷. Here's what I've tried:Which returns:
I expected the
z
keys in thedata
maps to be set to999
. Works as expected when removing theNode
wrappers. Also works when usingjp.Expr.Set()
.I didn't see any references to
Indexed
orKeyed
in https://github.com/ohler55/ojg/blob/develop/jp/modify.go, so I'm thinking thatModify
just does't currently support them. I would love to help out and add that myself, but honestly that code is a bit beyond me 😞. Is there any chance you'd be interested in doing so?The text was updated successfully, but these errors were encountered: