Disabling sorting mechanism in pprint output

Python 3.8 or newer: Use sort_dicts=False: pprint.pprint(data, sort_dicts=False) Python 3.7 or older: You can monkey patch the pprint module. import pprint pprint.pprint({“def”:2,”ghi”:3,”abc”:1,}) pprint._sorted = lambda x:x # Or, for Python 3.7: # pprint.sorted = lambda x, key=None: x pprint.pprint({“def”:2,”ghi”:3, “abc”:1}) Since the 2nd output is essentiallly randomly sorted, your output may be different from mine: … Read more

Which pretty print library? [closed]

In no particular order: The “Free” in Text.PrettyPrint.Free means free monad, as per the package description: “A free monad based on the Wadler/Leijen pretty printer”; its Doc type is parametrised on another type, and it has a Monad instance, allowing you to embed “effects” into Doc values. This is used by wl-pprint-terminfo to add formatting … Read more

How to Pretty print VBA code?

You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files “out of the box” – Visual Basic included! Download & install it, fire it up, and load up your VBA code. You should automatically see … Read more

JavaScript: How can I generate formatted easy-to-read JSON straight from an object? [duplicate]

JSON.stringify takes more optional arguments. Try: JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, 4); // Indented 4 spaces JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}, null, “\t”); // Indented with tab From: How can I beautify JSON programmatically? It should work in modern browsers, and it is included in json2.js if you need a fallback for browsers that don’t support the JSON helper functions. For display … Read more

Pretty print json but keep inner arrays on one line python

Here is a way to do it with as least amount of modifications as possible: import json from json import JSONEncoder import re class MarkedList: _list = None def __init__(self, l): self._list = l z = { “rows_parsed”: [ MarkedList([ “a”, “b”, “c”, “d” ]), MarkedList([ “e”, “f”, “g”, “i” ]), ] } class CustomJSONEncoder(JSONEncoder): … Read more