Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to format large JSON file? (~30 mb)

I need to format a large JSON file for readability, but every resource I've found (mostly online) doesn't deal with data say, above 1-2 MB. I need to format about 30 MB. Is there any way to do this, or any way to code something to do this?

like image 983
covariance Avatar asked Nov 09 '13 11:11

covariance


People also ask

How should JSON files be formatted?

JSON File StructureJSON data is written in key/value pairs. The key and value are separated by a colon(:) in the middle with the key on the left and the value on the right. Different key/value pairs are separated by a comma(,). The key is a string surrounded by double quotation marks for example “name”.

Is JSON good for big data?

Although JSON is referred to as comparatively better than CSV when dealing with massive data sets and in terms of scalability of files or applications, you should avoid this format when working with big data. There are more efficient alternatives.


1 Answers

With python >= 2.6 you can do the following:

For Mac/Linux users:

cat ugly.json | python -mjson.tool > pretty.json 

For Windows users (thanks to the comment from dnk.nitro):

type ugly.json | python -mjson.tool > pretty.json 
like image 182
pstadler Avatar answered Nov 15 '22 23:11

pstadler