I have an array of JSON object. The sample array is as follows:
[
{
"evt.category": "file",
"evt.cpu": 0,
"evt.num": 10078507,
"evt.res": "SUCCESS",
"evt.time": 1532841047277584400,
"evt.type": "read",
"fd.filename": "libnss_files.so.2",
"fd.name": "/lib/x86_64-linux-gnu/libnss_files.so.2",
"fd.num": 13,
"fd.type": "file",
"fd.uid": "1996913",
"proc.loginshellid": 19968,
"proc.name": "last",
"proc.pid": 19969,
"thread.ismain": true,
"thread.tid": 19969
},
{
"evt.buffer": "1000",
"evt.category": "file",
"evt.cpu": 0,
"evt.num": 10078564,
"evt.res": "SUCCESS",
"evt.time": 1532841047277731300,
"evt.type": "read",
"fd.filename": "loginuid",
"fd.name": "/proc/16009/loginuid",
"fd.num": 13,
"fd.type": "file",
"fd.uid": "1996913",
"proc.loginshellid": 19968,
"proc.name": "last",
"proc.pid": 19969,
"thread.ismain": true,
"thread.tid": 19969
},
{
"evt.buffer": "",
"evt.category": "file",
"evt.cpu": 0,
"evt.num": 10078566,
"evt.res": "SUCCESS",
"evt.time": 1532841047277733400,
"evt.type": "read",
"fd.filename": "loginuid",
"fd.name": "/proc/16009/loginuid",
"fd.num": 13,
"fd.type": "file",
"fd.uid": "1996913",
"proc.loginshellid": 19968,
"proc.name": "last",
"proc.pid": 19969,
"thread.ismain": true,
"thread.tid": 19969
}
]
I want to re-structure this array such that each object is converted into another array and each array should contain JSON objects on the basis of these keys like a JSON object of evt , proc thread etc.
I tried some online websites to do that but none of it work.
Please Help.
EDIT: My desired output is as follows:
[
{
"evt": {
"category": "file",
"cpu": 0,
"num": 10078507,
"res": "SUCCESS",
"time": 1532841047277584400,
"type": "read"
},
"fd": {
"filename": "libnss_files.so.2",
"name": "/lib/x86_64-linux-gnu/libnss_files.so.2",
"num": 13,
"type": "file",
"uid": "1996913"
},
"proc": {
"loginshellid": 19968,
"name": "last",
"pid": 19969
},
"thread": {
"ismain": true,
"tid": 19969
}
},
{
"evt": {
"buffer": "1000",
"category": "file",
"cpu": 0,
"num": 10078564,
"res": "SUCCESS",
"time": 1532841047277731300,
"type": "read"
},
"fd": {
"filename": "loginuid",
"name": "/proc/16009/loginuid",
"num": 13,
"type": "file",
"uid": "1996913"
},
"proc": {
"loginshellid": 19968,
"name": "last",
"pid": 19969
},
"thread" : {
"ismain": true,
"tid": 19969
}
}
]