0

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

JSands
  • 133
  • 7
  • 1
    There are sites which validate json files, like https://jsonformatter.curiousconcept.com/. I pasted your file there and got lots of errors. Fix them, your code might work better. – John Bayko Aug 09 '21 at 00:04

1 Answers1

0

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.

JSands
  • 133
  • 7