How to remove object in json file via linux command

satyarankireddy

New Member
I have json file which is placed into Linux server. I want to delete particular object from second position onward.
Issues:-
1. Root element keep it and same object which is repeated in json file has to be removed.
2. how to append box brackets in json data

Note: We don't have access to install JP in Linux sever we have to achieve this via sed or awk or any Linux shell commands.

i tired sed and awk command but no luck

sed '/"audit"/,/}/ d; /^$/d' sample_request.json >> test.json -- This command was deleting entire object instead of particular word.


audit: -- Remove this object in json file from second position on wards.
[] -- This box brackets are needs to append to file which is show as excepted output

Actual:-

{
"audit" : {
"audit number" : "123",
"amount" : {
"Amount" : -10.0,
"code" : "abc"
},
"over" : 1
},
"audit" : : {
"audit number" : "234",
"amount" : {
"Amount" : 290.0,
"code" : "xyz"
},
"over" : 5
},
"audit" : {
"audit number" : "235",
"amount" : {
"Amount" : 270.0,
"code" : "kdb"
},
"over" : 6
},
"id" : "test",
"eid" : "1",
"bcode" : "123",
"wid" : "1234",
"wsid" : "11",
"ss" : 2
}
Excepted output like below:

{
"audit" :[{
"audit number" : "123",
"amount" : {
"Amount" : -10.0,
"code" : "abc"
},
"over" : 1
},
{
"audit number" : "234",
"amount" : {
"Amount" : 290.0,
"code" : "xyz"
},
"over" : 5
},
{
"audit number" : "235",
"amount" : {
"Amount" : 270.0,
"code" : "kdb"
},
"over" : 6
},
]
"id" : "test",
"eid" : "1",
"bcode" : "123",
"wid" : "1234",
"wsid" : "11",
"ss" : 2
}
 
Last edited:


wizardfromoz

Super Moderator
Staff member
Gold Supporter
Hello @satyarankireddy and welcome to linux.org :), also Hi to @Larryc

I'm moving this Thread to Command Line where other answers may be attracted as well.

Good luck

Chris Turner
wizardfromoz
 

Members online

No members online now.

Top