Reputation: 93
I have two json
files. If I am trying to add them into a single one, it is showing a parse error.
Can anyone explain how to rectify this?
The two files are: config.json
{ "config" :
[
{
"IP": "10.97.05.212",
"PORT": 80,
"USERNAME": "admin",
"ENABLE" : "False",
},
{
"IP": "10.27.19.178",
"PORT": 80,
"USERNAME": "admin",
},
{
"IP": "10.26.16.198",
"PORT": 80,
"USERNAME": "admin",
},
{
"IP": "10.47.45.196",
"PORT": 80,
"USERNAME": "admin",
},
{
"IP": "10.37.67.160",
"PORT": 80,
"USERNAME": "admin",
}
]}
config1.json
{
"IP": "10.27.21.79",
"PORT": 14564,
"USERNAME": "admin",
}
{
"IP": "10.27.21.79",
"PORT": 14563,
"USERNAME": "admin",
}
{
"IP": "10.27.21.79",
"PORT": 14566,
"USERNAME": "admin",
}
jq -n 'input | .config += [inputs]' config.json config1.json
jq ' .[] += [ input ]' config.json config1.json
jq -s add config.json database.db
jq --slurp . config.json config1.json
I have used above jq
commands to do the task. But getting the same parse error:
Expected value before ','
Can anyone explain how to do rectify this error?
Upvotes: 2
Views: 4074
Reputation: 116750
Since config1.json is a stream of JSON entities, you could use the --slurpfile option:
jq --slurpfile config1 config1.json '.config += $config1' config.json
Upvotes: 1