MathCurvesSurfacesWallpaper GroupsGallerySoftwarePOV-Ray
ProgramingLinuxPerl PythonHTMLCSSJavaScriptPHPJavaEmacsUnicode ♥
Web Hosting by 1&1

Parse JSON in PHP & Python

Xah Lee, ,

Here's quick way to pretty-print JSON string using PHP and Python

<?php
// can be some complex, page-long JSON data
$jsonString = <<<'HHHHH'
{"some":"thing"}
HHHHH;
var_dump(json_decode( $jsonString ));
?>
#python 2
import json

# can be complex page-long JSON data
jsonString = '''{"some":"thing"}'''

jsonObject = json.loads(jsonString)

print json.dumps( jsonObject, indent=2)

thanks to https://twitter.com/yud1z and agu monkey

blog comments powered by Disqus