pretty-print tagged requests and articles

Categorized request examples and articles tagged with [pretty-print] keyword
How to dump Python object to JSON using json.dumps()?
To dump a Python object to JSON string, you can use the json.dumps() method of the built-in json module. The json.dump() paired method (without the "s") converts the Python object to JSON string and writes it to a file. By passing indent and sort_keys parameters to the json.dumps() and json.dump() methods, you can pretty-print the result JSON, otherwise, a compact JSON will be generated. If your Python object contains a non-basic objects, the json.dumps() method will throw an exception. By passing the skipkeys=True, you can tell json.dumps() to ignore such objects instead of throwing an exception. In this Python JSON Dumps example, we are serializing a basic Python object to a JSON string. More advanced Python to JSON examples are listed below. Click Execute to run the Python JSON Dumps example online and see the result.

How do I pretty print JSON in JavaScript?
To pretty-print JSON in JavaScript, you can use the JSON.stringify(obj, replacer, space) method. The third parameter of the JSON.stringify() method specifies the number of spaces to use when outputting the JSON string. If you pass a non-zero number, JSON.stringify() will generate pretty JSON with the specified number of white spaces in the JSON. If you pass 0, then JSON.stringify() will generate minified JSON. You can also pass a string instead of a number, which will be inserted instead of spaces. In this JavaScript Pretty Print JSON example, we use the JSON.stringify() method to print a JavaScript object in a human-readable format. Click Execute to run the JavaScript Pretty Print JSON example online and see the result.