-
Notifications
You must be signed in to change notification settings - Fork 366
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
ast.Node should support move and/or copy at any depth of the tree; not just within arrays #732
Comments
Yes, can you introduce your practical scenario |
In an application that does quite a bit of json munging reshaping, the prevailing solution is to use a combination of gjson and sjson. While I'm aware of the cloudwego.gjson as being faster (for lookups at least, if not walking a structure) I don't believe there's an equivalent to sjson. The ast seems to have methods for getting things by path, but not for setting by path. Furthermore, Unset only acts upon a parent node. let's say… for instance, that you have a structure like this: {
"foo": {
"w": 123,
"h": 345
}
} and you want to end up with {
"w": 123,
"h": 345
} It would be nice to be able to say Or, foo had more info, then moving just the width and height something like or… maybe some signature to move across different roots might be helpful too - should there be a ton of things on foo that wanted to move to bar… I guess it's all possible with combinations of get, unset, and set, but it does seem fairly verbose for clients to do. Another aspect of this is setting things at locations in the tree that don't exist yet, would be nice to do something like |
Similar to what I was saying about #731, given the starting point of {
"foo": {
"w": 123,
"h": 345
}
} You may wish to move from foo to bar (as a rename) to end up with {
"bar": {
"w": 123,
"h": 345
}
} |
Another aspect that may be a flag or something - not sure how often this would play in but just saying… there might be a desire to prune empty… {
"depth1": {
"depth2": {
"w": 123,
"h": 345
}
}
} If you move, say… "depth1.depth2" to "foobar" you might want to also delete depth1 since it will become empty at that point to end up with: {
"foobar": {
"w": 123,
"h": 345
}
} |
If some of the other feature issues are addressed, this may be straightforward to do as a client with a set and delete, but a copy/move (copy with delete of src) would be convenient for reshaping incoming fuzzy json generously into a schema that can parse naturally.
The text was updated successfully, but these errors were encountered: