fastjson
fastjson copied to clipboard
Consider provide a function in order to simply get *Value's parent key value
Hey! Thanks for such a great JSON framework. I am happy to use!
We could provide a string
field in *Value
struct or a function that called like: parentKey
or GetParentKey() string
Why we should need like these field or function is that actually is we can not get parent key's value from in *Value
context.
func get(v *fastjson.Value) {
var key string = v.GetParentKey()
}
We must use Visit
function in order to get key's value, which is not useful due to we must scan all of JSON's fields.
func get(v *fastjson.Value) {
v.Visit(func(key []byte, v *fastjson.Value) {
var key string = string(key)
})
}
A few GetParentKey()
examples:
{
"a": "foo",
"b": "bar",
"c": {
"d": "baz",
"e": 0
}
}
- If Value is at the top level (which means there is no parent key), it returns
nil
or""
. - If Value is at inside
c
key, it returns"c"
Thanks!
Hey @valyala, would you like any help with this issue? I am not making any promises but I'd be interested in looking into it, if you want.