Answer the question
In order to leave comments, you need to log in
How to sort json like on JSON placeholder?
There is a json file with 70k lines, is it possible to do something like on https://jsonplaceholder.typicode.com/todos?_page=2
Tobish page=1 - the first ten is displayed
page=2 - the second ten is displayed, etc.
Answer the question
In order to leave comments, you need to log in
You need to first convert your file (in which, apparently, there is a list at the top level) into a list of jsons nested in this list:
jq -c ".[]"
Then split into groups of N pieces:
split -l 10 -d - my_chunk_prefix_
We get my_chunk_prefix_* files, but each of them does not contain valid json, but json -strings. They need to be converted to regular josns.
for f in my_chunk_prefix_*; do cat $f | sed '1s/^/[/; $!s/$/,/; $s/$/]/' | jq "" > $f.json ; rm $f ; done
jq -c ".[]" my_big.json | split -l 10 -d - my_chunk_prefix_
for f in my_chunk_prefix_*; do cat $f | sed '1s/^/[/; $!s/$/,/; $s/$/]/' | jq "" > $f.json ; rm $f ; done
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question