simple exemple godot json

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

trying to learn how to work with json, you can write an example of how to output each element from such a json array separately to the list as I look at some complex examples I can not figure it out
first made a photo in the table attached

enter image description here
then attached the photo to json

enter image description here

how can I display it in a loop, for example, in buttons in via gdscript
in 1 button
1 samsung i710 2012

2 button
2 nokia n73 2013
3 button
3 siemens name 2014

:bust_in_silhouette: Reply From: IHate

Once you have your json file you need to parse it. As you parse it you can associate the values of each key to a button with variables or metadata. Then you need to manually connect the button signal “pressed” so you can pass this variable/metadata as an argument and finally a function would print every key of the dictionary in the variable/metadata.

:bust_in_silhouette: Reply From: rakkarage
extends Control

var _data := {
	"1" : {
		"name": "russian",
		"model": "i710",
		"year": 2012
	},
	"2" : {
		"name": "nokia",
		"model": "n73",
		"year": 2013
	},
	"3" : {
		"name": "siemens",
		"model": "name",
		"year": 2014
	}
}

func _ready():
	var json := to_json(_data)
	print(json)
	var dictionary : Dictionary = JSON.parse(json).result
	for key in dictionary:
		print(dictionary[key].name)

https://docs.godotengine.org/en/stable/classes/class_file.html

Can use File to open files and parse csv data. For example:
https://github.com/rakkarage/Gename/blob/main/Gename.gd

rakkarage | 2020-10-18 18:12