Convert the JSON documents to TOML using yq
(from https://kislyuk.github.io/yq/), and then back from TOML to JSON using tomlq
(from the same yq
distribution):
$ yq -t '.' file1 file2 | tomlq .
{
"attributes": [
{
"name": "Node",
"value": "test"
},
{
"name": "version",
"value": "11.1"
}
]
}
This works because yq -t
creates the concatenation of the two TOML documents
[[attributes]]
name = "Node"
value = "test"
and
[[attributes]]
name = "version"
value = "11.1"
Together, according to the rules of TOML, this happens to be equivalent of the JSON document that you are looking to create (by virtue of attributes
being an array). So when tomlq
converts it back to JSON, it does the right thing.
You can do the equivalent transformations using the yj
utility (from https://github.com/sclevine/yj) too:
yj -tj < <( cat <( yj -jt <file1 ) <( yj -jt <file2 ) )
or, without the process substitutions and the cat
,
{ yj -jt <file1; yj -jt <file2; } | yj -tj
It turns out you could do the same type of round-trip via Hashicorp's HCL format too, using yj -jc
and yj -cj
in place of yj -jt
and yj -tj
respectively.