Hi akil
You request is very difficult to understand and ambiguous at best. Do not be surprise if the solutions are not close to what you wish.
It would had helped if you would had shown the desired output. Since the manipulation of the json posted would have to be handled by the python script test.py, it would had helped, as well, to see what it has.
Here's some points for whatever is worth to you, since the posted json is a non-valid fragment.
Example of deleting entries you do not want.
import json
some_json_string = '''
{
"something": [{
"time": 1520460953,
"Parameters1": [{
"group": "tag",
"item": "else"
},
{
"group": "url",
"item": "https://xxx.con"
},
{
"group": "tget",
"item": "a73927xxxxx"
}
],
" ite": " 1877",
"type": "impression",
"userId": "da52yjnh"
},
{
"time": 1520460953,
"Parameters1": [{
"group": "tag",
"item": "else"
},
{
"group": "url",
"item": "https://xxx1.con"
},
{
"group": "tget",
"item": "a73927fayyy"
}
],
" ite": "9222 ",
"type": "impression",
"userId": " jxbccyqsl"
}
]
}
'''
data = json.loads(some_json_string)
print("ORIGINAL json")
print(some_json_string)
for a in data['something']:
a['Parameters1'] = a['Parameters1'][1]
new_some_json_string = json.dumps(data, indent=2)
print("MODIFIED json")
print(new_some_json_string)
Output:
ORIGINAL json
{
"something": [{
"time": 1520460953,
"Parameters1": [{
"group": "tag",
"item": "else"
},
{
"group": "url",
"item": "https://xxx.con"
},
{
"group": "tget",
"item": "a73927xxxxx"
}
],
" ite": " 1877",
"type": "impression",
"userId": "da52yjnh"
},
{
"time": 1520460953,
"Parameters1": [{
"group": "tag",
"item": "else"
},
{
"group": "url",
"item": "https://xxx1.con"
}
},
{
"group": "tget",
"item": "a73927fayyy"
}
],
" ite": "9222 ",
"type": "impression",
"userId": " jxbccyqsl"
}
]
}
MODIFIED json
{
"something": [
{
"time": 1520460953,
"Parameters1": {
"group": "url",
"item": "https://xxx.con"
},
" ite": " 1877",
"type": "impression",
"userId": "da52yjnh"
},
{
"time": 1520460953,
"Parameters1": {
"group": "url",
"item": "https://xxx1.con"
},
" ite": "9222 ",
"type": "impression",
"userId": " jxbccyqsl"
}
]
}
Of course, this is JUST an example where I have to make the json valid and correct even the Parameters1
key since in the posted portion one of them has a leading space and the other doesn't.