【问题标题】:Cleaning up JSON Extract in MySQL在 MySQL 中清理 JSON 提取
【发布时间】:2021-01-29 10:08:12
【问题描述】:

这个 json_extract 有效,但很乱,我想清理它,但我不知道如何。

json_unquote(json_extract(
    json_unquote(json_extract(
        json_unquote(json_extract(
            json_unquote(json_extract(
                json_unquote(json_extract(
                    json_unquote(json_extract(response, '$.output')), '$.output')), '$.risk_score_model_result')), '$.value')), '$.ModelInputs')), '$.fieldname')) as fieldname;

我尝试使用->->>,但我只能让它工作一层深。例如,response -> '$.output' 有效,但是 response ->> '$.output' ->> '$.output'->->> 的任何变体都会引发语法错误。

对于 MySQL 和 json 提取,我是一个新手(显然),所以提前感谢您的帮助。

【问题讨论】:

    标签: mysql sql json string


    【解决方案1】:

    我认为你在这里把事情复杂化了。 json_extract()->->> 都采用 JSON path 作为参数。所以这个:

    response ->> '$.output' ->> '$.output'
    

    应该写成:

    response ->> '$.output.output'
    

    如果我们将相同的逻辑应用于您的大嵌套表达式,我认为应该变成:

    response ->> '$.output.output.risk_score_model_result.value.ModelInputs.fieldname'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2013-10-05
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多