Godot 4.2.1
Loaded JSON from a file:
var jsonStr := FileAccess.get_file_as_string(json_path)
var jsonData: Dictionary = JSON.parse_string(jsonStr)
This is the content of the JSON file:
{
"metaX": "metaX value",
"filters": [
{
"name": "someName_1_1",
"filters": [
{
"name": "someName2_1",
"items": [
"thing3_1_1",
"thing3_1_2"
]
},
{
"name": "someName2_2",
"items": [
"thing3_2_1",
"thing3_2_2"
]
}
]
},
{
"name": "someName_1_2",
"filters": [
{
"name": "someName2b_1",
"items": [
"thing3b_1_1",
"thing3b_1_2"
]
},
{
"name": "someName2b_2",
"items": [
"thing3b_2_1",
"thing3b_2_2"
]
}
]
}
]
}
Grabbing the first “filters” key/val and it returns a typeOf = Array:
var filterArr: Array = jsonData["filters"]
Expected behavior seems like ‘filterArr’ would have two Dictionary objects. (someName_1_1 and someName_1_2)
Instead, I get size=3 – typeOf is Dictionary, Dictionary, String.
filterArr contains the descendant objects starting with someName_1_1 instead of the sibling objects.
When I loop over the array and print to the console, I get:
{ "name": "someName_1_1", "desc": "someDesc_1_1", "filters": [{ "name": "someName2_1", "desc": "someDesc2_1", "items": ["thing3_1_1", "thing3_1_2"] }, { "name": "someName2_2", "desc": "someDesc2_2", "items": ["thing3_2_1", "thing3_2_2"] }] }
{ "name": "someName2_1", "desc": "someDesc2_1", "items": ["thing3_1_1", "thing3_1_2"] }
thing3_1_1
It’s like it grabbed the first object of each descendant.
This is weird, right? Am I using this incorrectly? Is there a bug with Dictionary?