validating JSON from command line using `python -m

2020-06-07 05:00发布

I have a data.json file that I'm validating through the command line using python's json.tool, but it keeps giving me back an error message:

$ python -m json.tool < data.json
No JSON object could be decoded

Here are the contents of data.json:

$ cat data.json
{ "fields": 
    [
        [ "first_name", null, {} ],
        [ "last_name", null, {} ],
        [ "addr1", null, {} ],
        [ "addr2", null, {} ],
        [ "city", null, {} ],
    ]
}

I don't have a problem with single quotes, nor is the file empty (obviously), so I'm not sure what's causing the problem here.

1条回答
来,给爷笑一个
2楼-- · 2020-06-07 05:45

It was because of the trailing comma after the last nested list [ "city", null, {} ]. I accidentally left it in and JSON doesn't allow them.

查看更多
登录 后发表回答