
The Fastest Way to Parse JSON in Python (Benchmark of 5 Libraries)
I needed to parse 2GB of JSON logs per day. Python's built-in json module was too slow. So I benchmarked every JSON library I could find. The Contenders json — Python stdlib ujson — C extension, drop-in replacement orjson — Rust-based, fastest option rapidjson — C++ wrapper simdjson — SIMD-accelerated parsing The Benchmark import json import time # Generate test data: 100K JSON objects data = [{ " id " : i , " name " : f " user_ { i } " , " email " : f " user_ { i } @test.com " , " scores " : [ i * 0.1 , i * 0.2 , i * 0.3 ], " active " : i % 2 == 0 } for i in range ( 100_000 )] json_str = json . dumps ( data ) def bench ( name , parse_fn , dumps_fn , iterations = 10 ): # Parse benchmark start = time . perf_counter () for _ in range ( iterations ): parse_fn ( json_str ) parse_time = ( time . perf_counter () - start ) / iterations # Serialize benchmark start = time . perf_counter () for _ in range ( iterations ): dumps_fn ( data ) dumps_time = ( time . perf_counter () - start ) / iterati
Continue reading on Dev.to Python
Opens in a new tab




