Closed ForceFaction closed 1 year ago
Your JSON doesn't validate.
Do you mean
{
"key": "val",
"list": [{
"key1": {
"\"key2\"": "val1"
}
}]
}
Hm sry, i actually mean:
{
"key": "val",
"list": [{
"key1": "{\"key2\": \"val1\"}"
}]
}
func main() {
// Parse JSON:
pj, err := simdjson.Parse([]byte(`{
"key": "val",
"list": [{
"key1": "{\"key2\": \"val1\"}"
}]
}`), nil)
if err != nil {
log.Fatal(err)
}
iter := pj.Iter()
list, err := iter.FindElement(nil, "list")
if err != nil {
log.Fatal(err)
}
arr, err := list.Iter.Array(nil)
if err != nil {
log.Fatal(err)
}
arr.ForEach(func(i simdjson.Iter) {
if i.Type() != simdjson.TypeObject {
return
}
elem, err := i.FindElement(nil, `key1`)
if err != nil {
return
}
fmt.Println(elem.Iter.String())
})
// Output:
// {"key2": "val1"} <nil>
}
{"key2": "val1"}
is a string, so it is returned as that. It will not be parsed. You will have to do that once you have the value.
Hi, i'm trying to parse JSON with the following structure:
I can't seem to find out how to get val1.