使用jq解释JSON中的嵌套JSON [英] Use jq to interpret nested JSON in JSON

查看:67
本文介绍了使用jq解释JSON中的嵌套JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找使用jq自动解析包含json作为json的任何字段的方法,例如:

I'm looking to use jq to automatically resolve any field which contains json as json, example:

输入

{
  "guaranteedPrizes": "[]",
}

输出

{
  "guaranteedPrizes": [],
}

推荐答案

对于一般解决方案,您可能希望考虑 walk/1 ,并且为了提高效率,请避免调用 fromjson 多余:

For a generic solution, you might wish to consider walk/1, and for efficiency, avoid calling fromjson redundantly:

walk(if type == "string"
     then . as $x | try fromjson catch $x
     else . end)

这篇关于使用jq解释JSON中的嵌套JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆