I would like to flatten a json file in order to meet the needs of a legacy program. I would prefer to use jq
for this as I know it is available to me.
I have a file something like this:
<code>[
{
"field1":10,
"field2":20,
"msg":
{
"a":1,
"b":2,
"c":3
},
}, ...
]
</code>
<code>[
{
"field1":10,
"field2":20,
"msg":
{
"a":1,
"b":2,
"c":3
},
}, ...
]
</code>
[
{
"field1":10,
"field2":20,
"msg":
{
"a":1,
"b":2,
"c":3
},
}, ...
]
For reasons, I need to pull the a and b fields from msg
and flatten their names:
<code>[
{
"field1":10,
"field2":20,
"msg.a":1,
"msg.b":2,
"msg": # the entire msg structure is now optional; if it falls off that's ok
{
"a":1,
"b":2,
"c":3
},
}, ...
]
</code>
<code>[
{
"field1":10,
"field2":20,
"msg.a":1,
"msg.b":2,
"msg": # the entire msg structure is now optional; if it falls off that's ok
{
"a":1,
"b":2,
"c":3
},
}, ...
]
</code>
[
{
"field1":10,
"field2":20,
"msg.a":1,
"msg.b":2,
"msg": # the entire msg structure is now optional; if it falls off that's ok
{
"a":1,
"b":2,
"c":3
},
}, ...
]
How is the miracle accomplished?