数据湖探索 DLI-字符串函数:JSON_VALUE

时间:2024-11-16 13:21:39

JSON_VALUE

  • 功能描述

    获取json字符串中指定path的值。

  • 语法
    VARCHAR JSON_VALUE(VARCHAR content, VARCHAR path)
  • 参数说明
    • content:输入字符串。
    • path:要获取的path路径。
  • 示例
    • 测试语句
      SELECT JSON_VALUE(content, path) AS case_result FROM T1;
    • 测试数据和结果
      表9 测试数据和结果

      测试数据(content,path)

      测试结果(case_result)

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      $

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      $.a1

      v1

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      $.a4

      {"a41":"v41","a42": ["v1","v2"]}

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      $.a4.a42

      ["v1","v2"]

      { "a1":"v1","a2":7,"a3":8.0,"a4": {"a41":"v41","a42": ["v1","v2"]}}

      $.a4.a42[0]

      v1

support.huaweicloud.com/sqlref-flink-dli/dli_08_0096.html