Remove lines from multiline json

Hi ,
When extracting the data from API end point ,its giving multi line json .I want to remove certain lines with
group": "tag" or tget and respect "item" values [only want to keep group": "url and along with rest of values.Any idea how to remove

python test.py /data{" Id":" 7554317""group":"get", "item":"xx5e1"],"fields":[" Id","type"," Parameters","xx"]}


 {
      "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"
    },

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.

When trying to execute ,getting the following error message

import json
data = json.loads("/xx/sites_extract_1.json")
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)

Traceback (most recent call last):
File "test1.py", line 2, in <module>
data = json.loads("/xx/sites_extract_1.json")
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

---------- Post updated at 01:06 AM ---------- Previous update was at 01:01 AM ----------

expecting output

"time": 1520460953,
      " Parameters1": [
  
        {
          "group": "url",
          "item": "https://xxx.con"
        }
   
      ],
      " ite": " 1877",
      "type": "impression",
      "userId": "da52yjnh"
    },

Essentially, it is telling you that it is no valid json.
I gave you an example of how to load a json string. You are passing it what it appears to be a file path.
Maybe:

with open('/xx/sites_extract_1.json') as data_file:   
    data = json.load(data_file)

Thanks Aia,working fine