簡體   English   中英

Snowflake 解析 JSON 時出錯:未完成的字符串,pos<number></number>

[英]Snowflake Error parsing JSON: unfinished string, pos <number>

我正在嘗試從雪花中的“天氣”表中查詢一個名為“JsonCode”的 varchar 列。 “JsonCode”列如下所示:

{
  "Date": "2019-11-07T12:28:18",
  "CurrentTemp": "47°F",
  "WeatherIconStatus": "clear-day",
  "LowTemp": "21°F",
  "HighTemp": "50°F",
  "WindSpeed": "6 mph",
  "TempCategory": "Hot",
  "ForecastData": [
    {
      "Date": "2019-11-08T00:00:00",
      "WeatherIconStatus": "clear-day",
      "LowTemp": "26°F",
      "HighTemp": "51°F",
      "WindSpeed": "3 mph"
    },
    {
      "Date": "2019-11-09T00:00:00",
      "WeatherIconStatus": "clear-day",
      "LowTemp": "28°F",
      "HighTemp": "56°F",
      "WindSpeed": "7 mph"
    }
  ],
  "PrecipitationReportData": {
    "ReportDateTimeAsDate": "2019-11-07T04:45:14",
    "PrecipitationConditions": "",
    "ForecastText": "Clear",
    "NewPrecipitationReadings": {
      "Overnight": {
        "PrecipitationReading": "0in"
      },
      "TwentyFourHours": {
        "PrecipitationReading": "0in"
      },
      "FortyEightHours": {
        "PrecipitationReading": "0in"
      },
      "SevenDays": {
        "PrecipitationReading": "0in"
      }
    },
    "AreaReadings": {
      "City": {
        "PrecipitationReading": "0in"
      },
      "Town": {
        "PrecipitationReading": "0in"
      },
      "Highway": {
        "PrecipitationReading": null
      }
    },
    "SeasonPrecipitation": {
      "PrecipitationReading": "44in"
    }
  },
  "Links": [
    {
      "Href": "https://weather.com",
      "Rel": "self",
      "Method": "GET"
    }
  ]
}

我特別想從 2019-11-07 獲取“WindSpeed”數據。 我創建了一個看起來像這樣的查詢。

SELECT value:WindSpeed::varchar FROM "DATABASE"."DBO"."WEATHER" 
    , lateral flatten(input => PARSE_JSON(JsonCode):windspeed);

我收到的回復是

Error parsing JSON: unfinished string, pos <number>

我一直無法找到有關此錯誤的任何文檔。 任何幫助表示贊賞。 注意:我刪除了一些 Json,因為有多天的預測數據。

這應該可以在不需要橫向展平的情況下工作:

select parse_json(j):WindSpeed
from data

使用發布的示例 JSON:

with data as (
select $${
  "Date": "2019-11-07T12:28:18",
  "CurrentTemp": "47°F",
  "WeatherIconStatus": "clear-day",
  "LowTemp": "21°F",
  "HighTemp": "50°F",
  "WindSpeed": "6 mph",
  "TempCategory": "Hot",
  "ForecastData": [
    {
      "Date": "2019-11-08T00:00:00",
      "WeatherIconStatus": "clear-day",
      "LowTemp": "26°F",
      "HighTemp": "51°F",
      "WindSpeed": "3 mph"
    },
    {
      "Date": "2019-11-09T00:00:00",
      "WeatherIconStatus": "clear-day",
      "LowTemp": "28°F",
      "HighTemp": "56°F",
      "WindSpeed": "7 mph"
    }
  ],
  "PrecipitationReportData": {
    "ReportDateTimeAsDate": "2019-11-07T04:45:14",
    "PrecipitationConditions": "",
    "ForecastText": "Clear",
    "NewPrecipitationReadings": {
      "Overnight": {
        "PrecipitationReading": "0in"
      },
      "TwentyFourHours": {
        "PrecipitationReading": "0in"
      },
      "FortyEightHours": {
        "PrecipitationReading": "0in"
      },
      "SevenDays": {
        "PrecipitationReading": "0in"
      }
    },
    "AreaReadings": {
      "City": {
        "PrecipitationReading": "0in"
      },
      "Town": {
        "PrecipitationReading": "0in"
      },
      "Highway": {
        "PrecipitationReading": null
      }
    },
    "SeasonPrecipitation": {
      "PrecipitationReading": "44in"
    }
  },
  "Links": [
    {
      "Href": "https://weather.com",
      "Rel": "self",
      "Method": "GET"
    }
  ]
}$$ j
)

select parse_json(j):WindSpeed
from data

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM