Make JSONPath work with unmarshalled JSON
oleksiys opened this issue · 1 comments
It's an interesting library, I wish it was even more abstract and allowed to use JSONPath features on already unmarshalled JSON, like:
if err := json.Unmarshal(someJSON, &v); err != nil {
log.Fatal(err)
}
objs, err := ajson.JSONPath2(v, path)
if err != nil {
log.Fatal(err)
}
Potentially JSONPath2 can return a list of *Node, but it's important for Nodes to keep connection with original "&v" so if I modify a node the modification is propagated to v.
I looked at the code and couldn't find an easy way to do that, because currently jsonpath and Node are tightly coupled with marshalling/unmarshilling optimizations, like keeping reference to the source JSON []byte, mark nodes dirty etc.
WDYT?
Hello,
Thanks! I suppose it would be very troublesome, because some of the types are not editable (even with references). In this case we should use reflections, first of all, and work with the base object only.
I see the benefits, and the main - we can use it as a "property accessor", but in this case library should be rewritten.
Thanks for proposal, I'll think about creation of new library property accessor for Golang
.