How can I beautify JSON programmatically? [duplicate]

Programmatic formatting solution: The JSON.stringify method supported by many modern browsers (including IE8) can output a beautified JSON string: JSON.stringify(jsObj, null, “\t”); // stringify with tabs inserted at each level JSON.stringify(jsObj, null, 4); // stringify with 4 spaces at each level Demo: http://jsfiddle.net/AndyE/HZPVL/ This method is also included with json2.js, for supporting older browsers. Manual … Read more

How to pretty print XML from Java?

Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, “yes”); transformer.setOutputProperty(“{http://xml.apache.org/xslt}indent-amount”, “2”); // initialize StreamResult with File object to save to file StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(doc); transformer.transform(source, result); String xmlString = result.getWriter().toString(); System.out.println(xmlString); Note: Results may vary depending on the Java version. Search for workarounds specific to your platform.

Javascript: How to 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? 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 purposes, … Read more

How to turn off the Eclipse code formatter for certain sections of Java code?

Eclipse 3.6 allows you to turn off formatting by placing a special comment, like // @formatter:off … // @formatter:on The on/off features have to be turned “on” in Eclipse preferences: Java > Code Style > Formatter. Click on Edit, Off/On Tags, enable Enable Off/On tags. It’s also possible to change the magic strings in the … Read more

How to prettyprint a JSON file?

The json module already implements some basic pretty printing in the dump and dumps functions, with the indent parameter that specifies how many spaces to indent by: >>> import json >>> >>> your_json = ‘[“foo”, {“bar”:[“baz”, null, 1.0, 2]}]’ >>> parsed = json.loads(your_json) >>> print(json.dumps(parsed, indent=4, sort_keys=True)) [ “foo”, { “bar”: [ “baz”, null, 1.0, … Read more

pretty-print JSON using JavaScript

Pretty-printing is implemented natively in JSON.stringify(). The third argument enables pretty printing and sets the spacing to use: var str = JSON.stringify(obj, null, 2); // spacing level = 2 If you need syntax highlighting, you might use some regex magic like so: function syntaxHighlight(json) { if (typeof json != ‘string’) { json = JSON.stringify(json, undefined, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)