"Complex" json file to dict reading (nor parsing,just reading)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MaximoTG98

So, i’m new in storage systems in godot, and for now i made a testing json database to save only 3 variables, a name, a cost, and a image path. Think of it as cards. Well, my problem is that when i get the godot dictionary with all of the info, I don’t know how to search in between keys:

*{
"sheets": [
	{
		"name": "cards",
		"columns": [
			{
				"typeStr": "1",
				"name": "NOMBRE"
			},
			{
				"typeStr": "3",
				"name": "COSTE",
				"opt": true,
				"display": null
			},
			{
				"typeStr": "1",
				"name": "RUTAIMAGEN",
				"display": null
			}
		],
		"lines": [
			{
				"NOMBRE": "Ataque",
				"RUTAIMAGEN": "res://resources/images/sword.png",
				"COSTE": 3
			},
			{
				"NOMBRE": "Defensa",
				"RUTAIMAGEN": "res://resources/images/shield.png",
				"COSTE": 5
			},
			{
				"NOMBRE": "Vida",
				"RUTAIMAGEN": "res://resources/images/heal.png",
				"COSTE": 1
			}
		],
		"separators": [],
		"props": {}
	}
],
"customTypes": [],
"compress": false

}*

This file was made in CastleDB, but I can’t manage to get into the “lines” key inside of the “sheets” key. I search on the docs and it isn’t there i opened an issue for clarification.

TL;DR How to get a key inside of another key in a dictionary.

  • I have a “sheets” key with another key inside of it called “lines” and “columns”. And inside of “lines” I have 3 arrays with another 3 values. So I don’t know how data.get(“sheets”/“lines”/“1…2…3/name”). I know this does not work but I don’t know how to make it properly.
:bust_in_silhouette: Reply From: omggomb

Once you parsed it, you can just use it like you would in JavaScript i.e. use dots to step through it or use strings as keys (link to docs):

parse_result.result.sheets[0].lines
or
parse_result.result.sheets[0]["lines"]

where parse_result is the object that is returned by JSON.parse.

:bust_in_silhouette: Reply From: maddytroupe

Please change the root quotes as single quotes