tseyanglim / VST

Vensim Script Tools for improving workflow in Vensim
GNU General Public License v3.0
4 stars 1 forks source link

Unclear meaning of json decoder #3

Closed hyunjimoon closed 2 years ago

hyunjimoon commented 2 years ago

With this control text file,

{
    "baserunname": "Covid",
    "simsettings": {
        "model": "CovidUSA-Econ-V79.mdl",
        "data": [
            "CovidModelInputs - ConstantDataStates.vdf",
            "CovidModelInputs - CRWStates.vdf",
            "CovidModelInputs - DeathDataStates.vdf",
            "CovidModelInputs - FlowDataStates.vdf",
            "CovidModelInputs - FormattedDataStates.vdf",
            "CovidModelInputs - TestDataStates.vdf",
            ], 
        "payoff": "PayoffFlowV77-Policy.vpd",
        "sensitivity": "", 
        "optparm": "COVID-V79-All.voc",
        "changes": [], 
        "savelist": "", 
        "senssavelist": ""
        },
    "venginepath": "C:/Program Files (x86)/Vengine2/Vensim - vengine.exe",
    "vensimpath": "",
    "graphs": "",
    "timelimit": 600,
    "mccores": 0
    }

I received the error

json.decoder.JSONDecodeError: Expecting value: line 12 column 4 (char 365)

but I am not sure what line 12 column 4 (char365) means. Also, from the code documentation as below could you please be more specific on "decode a JSON document from a string that may have extraneous data at the end."? Thanks.

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
        a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration as err:
            raise JSONDecodeError("Expecting value", s, err.value) from None
        return obj, end
tseyanglim commented 2 years ago

JSON decoder errors almost always mean some issue with the syntax of the control file, in the line indicated (the char number is less useful). In this case, under data, the list ends with a comma (in "CovidModelInputs - TestDataStates.vdf",), which is okay in Python but not for JSON.

The JSON decoder documentation isn't from me, it's from the json module :)