Format and validate JSON
Understand the architecture, parsing algorithms, and security implications of JSON processing in modern web applications.
The JSON Formatter operates entirely in your browser using a combination of the native JSON.parse() API for small payloads and a dedicated Web Worker for payloads exceeding 500KB.
When processing large JSON files (up to 5MB), the data is transferred to a background worker to prevent the main UI thread from freezing. This ensures the browser remains responsive (60fps) even while parsing millions of tokens.
JSON.parse() and JSON.stringify() with spacing arguments for beautification.PERF-01 (No main thread lock) rule.JSON parsing is vulnerable to Prototype Pollution and Denial of Service (DoS) if not handled properly.
Standard JSON parsing runs in O(N) time complexity, where N is the length of the string. However, sorting keys (A-Z) requires recursive traversal, increasing complexity to O(N log K) where K is the number of keys per object.
By shifting this computation to a Web Worker, we protect the UI thread. The memory cost is essentially 2-3x the file size because of the DOM String allocation, AST object creation, and final string serialization.
JSON parsing commonly fails on:
"key", not single quotes or unquoted.JSON.parse rounds large numbers (exceeding Number.MAX_SAFE_INTEGER). For financial data, strings are safer.Why might parsing a 10MB JSON file directly on the main thread be a bad idea?