将json转换为bash中的键/值文件 [英] transform json to key/value file in bash

查看:83
本文介绍了将json转换为bash中的键/值文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的JSON:

I have a JSON which looks like this:

{
    "lorem": "ipsum",
    "dolor": "sid",
    "data": {
        "key1": "value1",
        "key2": "value2"
    }
}

,我想要一个ini的输出,就像我只需要'data'的内容一样(它总是平坦的,没有分支).输出应如下所示:

and I want an output which is ini like where I only need the content of 'data' (which is always flat, no branches). The output should look like this:

key1=value1
key2=value2

我可以使用jq(只是不要使其运行),但是必须使用bash脚本.有人可以帮忙吗?

I can use jq (just don't get it running) but have to use a bash script for it. Can anyone help?

推荐答案

jq 解决方案:

jq solution:

jq -r '.data | to_entries[] | "\(.key)=\(.value)"' input.json

输出:

key1=value1
key2=value2

这篇关于将json转换为bash中的键/值文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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