0 votes

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.
in Engine by (108 points)

2 Answers

0 votes

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.

by (1,517 points)
0 votes

Please change the root quotes as single quotes

by (26 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.