【问题标题】:JSON Formatting errorJSON格式错误
【发布时间】:2016-11-18 05:02:04
【问题描述】:

我在尝试将此 JSON 导入谷歌 bigquery 表时遇到此错误 file-00000000:JSON 表遇到太多错误,放弃。行数:1;错误:1.(错误代码:无效) 文件中从位置 0 开始的行中的 JSON 解析错误:file-00000000。遇到没有对象开始的数组开始。 (错误代码:无效)

这是 JSON

[{'instrument_token': 11192834, 'average_price': 8463.45, 'last_price': 8471.1, 'last_quantity': 75, 'buy_quantity': 1065150, 'volume': 5545950, 'depth': {'buy': [{'price': 8471.1, 'quantity': 300, 'orders': 131072}, {'price': 8471.0, 'quantity': 300, 'orders': 65536}, {'price': 8470.95, 'quantity': 150, 'orders': 65536}, {'price': 8470.85, 'quantity': 75, 'orders': 65536}, {'price': 8470.7, 'quantity': 225, 'orders': 65536}], 'sell': [{'price': 8471.5, 'quantity': 150, 'orders': 131072}, {'price': 8471.55, 'quantity': 375, 'orders': 327680}, {'price': 8471.8, 'quantity': 1050, 'orders': 65536}, {'price': 8472.0, 'quantity': 1050, 'orders': 327680}, {'price': 8472.1, 'quantity': 150, 'orders': 65536}]}, 'ohlc': {'high': 8484.1, 'close': 8336.45, 'low': 8422.35, 'open': 8432.75}, 'mode': 'quote', 'sell_quantity': 998475, 'tradeable': True, 'change': 1.6151959167271395}]

http://jsonformatter.org/ 也会给出这个 JSON 块的解析错误。需要帮助了解格式错误的位置 - 这是来自 rest API 的 JSON

【问题讨论】:

    标签: json google-bigquery


    【解决方案1】:

    这不是有效的 JSON。 JSON 使用双引号,而不是单引号。另外,True 应该是 true

    如果我不得不猜测,我会猜测这是作为 JSON 传递的 Python 代码。 :-)

    我怀疑即使将其转换为正确的 JSON,它也不是 Google BigQuery 所期望的格式。从https://cloud.google.com/bigquery/data-formats#json_format 看来,您应该有一个文本文件,其中每行一个 JSON 对象。试试这个:

    {"mode": "quote", "tradeable": true, "last_quantity": 75, "buy_quantity": 1065150, "depth": {"buy": [{"quantity": 300, "orders": 131072, "price": 8471.1}, {"quantity": 300, "orders": 65536, "price": 8471.0}, {"quantity": 150, "orders": 65536, "price": 8470.95}, {"quantity": 75, "orders": 65536, "price": 8470.85}, {"quantity": 225, "orders": 65536, "price": 8470.7}], "sell": [{"quantity": 150, "orders": 131072, "price": 8471.5}, {"quantity": 375, "orders": 327680, "price": 8471.55}, {"quantity": 1050, "orders": 65536, "price": 8471.8}, {"quantity": 1050, "orders": 327680, "price": 8472.0}, {"quantity": 150, "orders": 65536, "price": 8472.1}]}, "change": 1.6151959167271395, "average_price": 8463.45, "ohlc": {"close": 8336.45, "high": 8484.1, "open": 8432.75, "low": 8422.35}, "instrument_token": 11192834, "last_price": 8471.1, "sell_quantity": 998475, "volume": 5545950}
    

    【讨论】:

    • JSONformatter.org 即使使用双引号也会出错
    • @ChandanKumar:但从根本上说,答案是:这不是 JSON,您可以自己轻松确定。不要手工制作 JSON,在您使用的任何语言/环境中构建结构,并使用适当的 JSON 序列化程序来创建 JSON。
    • 更新:此 JSON 在 JSONformatter.org 中显示为有效(单引号替换为双引号,True 替换为“True”)但 google bigquery 仍然给出相同的错误。
    • 从对象开始,而不是数组:{"data": [...]}
    • @smarx 谢谢..这是数据供应商以 JSON 形式传递的 python 代码:)。原始 JSON 也是行分隔格式(开始和结束在同一行)。与您发布的 JSON 相同的错误。
    【解决方案2】:

    OP 有一个有效的 JSON 记录,但它不适用于 Biq Query,原因如下:

    1. Google Big Query 支持 JSON 对象 {},每行一个对象。检查this
    2. 这基本上意味着您不能提供列表 [] 作为 json 记录并期望 Big Query 检测到它。每行必须始终有一个 json 对象。

    3. 这里是我所说的快速参考。

    还有更多。


    终于,

    我强烈建议您阅读以下内容并查看链接以获取有关不同形式 JSON 结构的更多信息,请从 json.org

    阅读此内容

    【讨论】:

      猜你喜欢
      • 2016-10-28
      • 2018-11-09
      • 2018-02-10
      • 2021-09-04
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多