У меня есть очень большие 5 ГБ json файл. Я пытаюсь удалить первый ключ из файла.
Вход:
{"url":"example.com","original_url":"http://example.com","text":"blah...blah"...}
Я попробовал:
jq 'del(.url)' file.json > out.josn
Эта команда хорошо работала, пока я не столкнулся с ошибкой:
aims@aims:~$ jq 'del(.url)' file.json > out.json
parse error: Invalid numeric literal at line 680284, column 49
Любезно, сообщите мне решение. В чем проблема jq
?
Загрузите json данные как словарь Python и вытолкайте определенный ключ
#!/usr/bin/env python
import json,sys
with open(sys.argv[1]) as f:
for line in f:
data=json.loads(line)
data.pop('url')
json.dump(data,sys.stdout)
print("")
Тест:
$ cat input.txt
{"url":"example.com","text":"blah...blah"}
{"url":"anotherexample.com","text":"blah...blah"}
$ ./pop_json_item.py input.txt
{"text": "blah...blah"}
{"text": "blah...blah"}