Search code examples
godotgdscript

Error parsing JSON at line 0: Expected '}'


I have to be missing something simple here. It loads the file just fine but will not parse it at all.

const vFile = "res://Data/Companions.json"

func _Parse():
    var vData = {}
    var file = File.new()
    
    assert(file.file_exists(vFile))

    var vError = file.open(vFile, File.READ)
    if vError != OK:
        Interface._Debug("Couldn't open file %s for reading. Error: %s." % [vFile, vError])

    while (!file.eof_reached()):
        vData = parse_json(file.get_line())
        assert(vData.size() > 0)
        #DO STUFF WITH vData
    file.close()

Companions.json


Solution

  • John Bayko was correct. I misunderstood the format of a json from a tutorial I watched. Once I followed John's advice and corrected my json file through a validator, the code worked as expected.