使用`python -m jsontool`从命令行验证JSON给出'无法解码JSON对象' [英] validating JSON from command line using `python -m jsontool` gives 'No JSON object could be decoded'

查看:493
本文介绍了使用`python -m jsontool`从命令行验证JSON给出'无法解码JSON对象'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个data.json文件,我正在使用python的json.tool通过命令行进行验证,但该文件不断向我返回错误消息:

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

以下是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.

推荐答案

这是由于最后一个嵌套列表[ "city", null, {} ]之后的逗号引起的.我不小心将其留在了其中,并且 JSON不允许它们.

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.

这篇关于使用`python -m jsontool`从命令行验证JSON给出'无法解码JSON对象'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆