JSON格式错误

Cha*_*mar 1 json google-bigquery

我在尝试将此JSON导入google bigquery表文件-000000时遇到此错误: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}]
Run Code Online (Sandbox Code Playgroud)

http://jsonformatter.org/也为此JSON块提供了解析错误.需要帮助了解格式错误的位置 - 这是来自其他API的JSON

use*_*559 7

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

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

我怀疑,即使将其转换为正确的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}
Run Code Online (Sandbox Code Playgroud)


gee*_*rsh 5

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

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

  3. 这是对我所说内容的快速参考。

(图片提供:json.org) 还有更多。


最后,

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