Save Json = SavesWrongData. how do i save a json by adding the JsonDict?

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

I thought saving to json with open was supposed to save as a text.json but mine is saving as encrypted or something.
I created a pastebin this time, The Code Sample always breaks on me

pastebin name SaveJson_SavesWrongData:
SaveJson_SavesWrongData - Pastebin.com

my json var:
onready var thing_to_save = {
“parent”: “minecraft:item/generated”,
“textures”: {
“layer0”: “minecraft:item/”+str(NewName)
}
}

What gets saved to the json file:
5c00 0000 0400 0000 5100 0000 7b22 7061
7265 6e74 223a 226d 696e 6563 7261 6674
3a69 7465 6d2f 6765 6e65 7261 7465 6422
2c22 7465 7874 7572 6573 223a 7b22 6c61
7965 7230 223a 226d 696e 6563 7261 6674
3a69 7465 6d2f 4e75 6c6c 227d 7d00 0000

if im not mystaken, godot is encrypting the data. even though i use open and not open_encrypted

any help would be much appreciated :slight_smile:

i fixed it by changing from store_var to store)line.

but now it prints all in one line and does not look good at all lol.

any ideas on how to fo fix this???

reapersremorse | 2022-01-20 20:52

i didnt want to do this but i ended up seperating each line in the json file and printing them seperately.

i would rather have a few nasty lines of code then have thousand of files that are hard to read.

this is my new save function and it PrettyPrints each json file.

func Save(PATH : String,NewName, thing_to_save):
var file = File.new()
var MIGenerated = "minecraft:item/generated"
file.open(PATH+NewName+".json", File.WRITE)
#file.store_line(to_json(thing_to_save)) #Works but all in 1 line
file.store_line("{")
file.store_line('\t"parent":"'+str(MIGenerated)+'",')
file.store_line('\t\t"textures": {')
file.store_line('\t\t"layer0": '+str(NewNewName)+'"')
file.store_line("\t}")
file.store_line("}")
file.close()

reapersremorse | 2022-01-20 21:24