DEV Community

Cover image for Working with JSON in Python

Working with JSON in Python

Sam Agnew on November 19, 2018

Often developers need to deal with data in various different formats and JSON, short for JavaScript Object Notation, is one of the most popular for...
Collapse
 
josegonz321 profile image
Jose Gonzalez

Hey Sam,

Ty for this post. I've been a .NET dev for over a decade now. And I'm a amazed at what Python can do with so little setup/code.

I typed some of this code and got the results you mentioned above. Hope to see more of these types of posts!

Collapse
 
cyprx profile image
Nam Nguyen

thanks for the post. however, i think it would be better if you show more detailed on the differences between those package, for example, loads and dumps speed.

Collapse
 
lyfolos profile image
Muhammed H. Alkan
eval(json_data)

Still works, not recommended.

Collapse
 
jeremywmoore profile image
Jeremy Moore

How about

ast.literal_eval(json_data)
Collapse
 
idkravitz profile image
Dmitry Kravtsov

Still works, not recommended :)

Collapse
 
smirza profile image
Suhail

Hi Sam,

Thanks for posting. Never used Ultra JSON in the past, will definitely give it a shot.

Collapse
 
rapidtables1 profile image
rapidtables

Awesome in depth article, I am also working with JSON with Python and JAVA, and I use these tools to help me validate and visualise JSON data.

codebeautify.org/jsonviewer
jsonformatter.org

Collapse
 
pavi2410 profile image
Pavitra Golchha • Edited

I never had the need to use any JSON module to work with JSON in Py or JS.

Collapse
 
idkravitz profile image
Dmitry Kravtsov • Edited

Well, thats a bad habbit if you do it with eval in Python. For unfiltered data ast.literal_eval is preferred, but it's still 4 times slower than builtin json.loads, so I don't see a reason to ignore it.

Collapse
 
nalani profile image
nalani5210

Using python to process JSON is more convenient than JAVA, great!
I also use some tools to process JSON, such as
jsonformatting.com/

Collapse
 
vovkd profile image
Vladimir Donets

ijson perfect for working with large json files.