如何从 json 数组获取配置单元中的字符串列表

How to get list of Strings in hive from a json array

我有以下 json 字符串

{
  "userId": 12345,
  "eligibleCountries": [
    {
      "Level": "COUNTRY",
      "Name": "MX"
    },
    {
      "Level": "COUNTRY",
      "Name": "US"
    },
    {
      "Level": "COUNTRY",
      "Name": "CA"
    }
  ]
}

我想得到

userID countries
12345 ["MX","US","CA"]

我可以使用 GET_JSON_OBJECT 获得 userID 但对于国家列表我们不能使用 GET_JSON_OBJECT。 我们怎样才能在蜂巢中得到这个。

你可以使用[*]

select get_json_object('{
  "userId": 12345,
  "eligibleCountries": [
    {
      "Level": "COUNTRY",
      "Name": "MX"
    },
    {
      "Level": "COUNTRY",
      "Name": "US"
    },
    {
      "Level": "COUNTRY",
      "Name": "CA"
    }
  ]
}','$.eligibleCountries[*].Name') as countries;