LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Closed Thread
  Search this Thread
Old 03-24-2019, 01:54 AM   #1
satyarankireddy
Member
 
Registered: Mar 2019
Posts: 48

Rep: Reputation: Disabled
How to remove object in json file via linux command


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 by satyarankireddy; 03-24-2019 at 06:07 AM.
 
Old 03-24-2019, 08:33 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,669

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

https://www.linuxquestions.org/quest...nd-4175650782/
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Empty a File, Delete N Lines From a File, Remove Matching String From a File, And Remove Empty/Blank Lines From a File In Linux LXer Syndicated Linux News 0 11-22-2017 12:30 PM
LXer: How to parse JSON string via command line on Linux LXer Syndicated Linux News 0 09-05-2013 06:32 PM
Allthough squid has 1 object, it still asks object to http server markraem Linux - Server 0 10-08-2007 11:40 AM
Shared object library that uses another shared object library Nightfox Programming 1 02-15-2006 10:00 PM
Event driven object-to-object: C++ template class mecanism ( NOT STL or STDC++) bretzeltux Programming 2 12-23-2003 02:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration