{"id":349,"date":"2015-04-16T21:15:01","date_gmt":"2015-04-16T19:15:01","guid":{"rendered":"http:\/\/www.cymbeline.ch\/?p=349"},"modified":"2017-12-16T23:00:23","modified_gmt":"2017-12-16T22:00:23","slug":"offline-json-pretty-printing","status":"publish","type":"post","link":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/","title":{"rendered":"Offline JSON Pretty Printing"},"content":{"rendered":"

Today when you’re dealing with Web APIs, you often find yourself in the situation of handling JSON, either in the input for these APIs or in the output, or both. Some browsers have the means to pretty print the JSON from their dev tools. But you don’t always have that opportunity. That’s why there are tools to pretty print JSON. I’ve found quite a few of them on the web, but all the ones I’ve found have one terrible flaw: they actually send the JSON you’re trying to pretty print to the server (*shudder*). I don’t want my JSON data (sensitive or not) to be sent to some random servers!<\/p>\n

All your JSON are belong to us!<\/h1>\n

Now as I wrote, I don’t particularly like the fact that my JSON data is sent over the wire for pretty printing. It may not be super secret or anything, but in these days, you cannot be careful enough. Besides, it’s completely unnecessary to do it. All you need is already in your browser! So I quickly built my own JSON pretty printer (and syntax highlighter). You can find it right here<\/a>.<\/p>\n

Offline JSON Pretty Printing to the Rescue<\/h1>\n

Actually, the design is very simple. All my JSON pretty printer is doing, is to take your JSON input and try to parse it as JSON in the browser.<\/p>\n

\r\nJSON.parse(yourJsonInput)\r\n<\/pre>\n

If that fails, I’m showing the parsing error and it’s done. If it succeeds, I get back a JavaScript object\/array\/value, which then I’m inspecting. For objects, I’m using basic tree navigation to go through all the properties and nested objects\/arrays\/values for pretty printing. That’s it, really simple. No need to transmit the data anywhere — it stays right in your browser!<\/strong><\/p>\n

So like it, hate it, use it or don’t: cymbeline.ch JSON Pretty Printer<\/a><\/p>\n

<\/p>","protected":false},"excerpt":{"rendered":"

Today when you’re dealing with Web APIs, you often find yourself in the situation of handling JSON, either in the input for these APIs or in the output, or both. Some browsers have the means to pretty print the JSON from their dev tools. But you don’t always have that opportunity. That’s why there are … Continue reading “Offline JSON Pretty Printing”<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[61],"tags":[12,54,74,44],"yoast_head":"\nOffline JSON Pretty Printing - Tales of a Code Monkey<\/title>\n<meta name=\"description\" content=\"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Offline JSON Pretty Printing - Tales of a Code Monkey\" \/>\n<meta property=\"og:description\" content=\"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/\" \/>\n<meta property=\"og:site_name\" content=\"Tales of a Code Monkey\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-16T19:15:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-16T22:00:23+00:00\" \/>\n<meta name=\"author\" content=\"roger\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"roger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/\",\"url\":\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/\",\"name\":\"Offline JSON Pretty Printing - Tales of a Code Monkey\",\"isPartOf\":{\"@id\":\"https:\/\/cymbeline.ch\/#website\"},\"datePublished\":\"2015-04-16T19:15:01+00:00\",\"dateModified\":\"2017-12-16T22:00:23+00:00\",\"author\":{\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\"},\"description\":\"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.\",\"breadcrumb\":{\"@id\":\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cymbeline.ch\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Offline JSON Pretty Printing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cymbeline.ch\/#website\",\"url\":\"https:\/\/cymbeline.ch\/\",\"name\":\"Tales of a Code Monkey\",\"description\":\"... the adventures of a guy making software.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cymbeline.ch\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916\",\"name\":\"roger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g\",\"caption\":\"roger\"},\"sameAs\":[\"https:\/\/www.cymbeline.ch\"],\"url\":\"https:\/\/cymbeline.ch\/author\/roger\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Offline JSON Pretty Printing - Tales of a Code Monkey","description":"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/","og_locale":"en_US","og_type":"article","og_title":"Offline JSON Pretty Printing - Tales of a Code Monkey","og_description":"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.","og_url":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/","og_site_name":"Tales of a Code Monkey","article_published_time":"2015-04-16T19:15:01+00:00","article_modified_time":"2017-12-16T22:00:23+00:00","author":"roger","twitter_misc":{"Written by":"roger","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/","url":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/","name":"Offline JSON Pretty Printing - Tales of a Code Monkey","isPartOf":{"@id":"https:\/\/cymbeline.ch\/#website"},"datePublished":"2015-04-16T19:15:01+00:00","dateModified":"2017-12-16T22:00:23+00:00","author":{"@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916"},"description":"An easy way to do JSON Pretty Printing offline, without any need to post your JSON data to any server.","breadcrumb":{"@id":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cymbeline.ch\/2015\/04\/16\/offline-json-pretty-printing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cymbeline.ch\/"},{"@type":"ListItem","position":2,"name":"Offline JSON Pretty Printing"}]},{"@type":"WebSite","@id":"https:\/\/cymbeline.ch\/#website","url":"https:\/\/cymbeline.ch\/","name":"Tales of a Code Monkey","description":"... the adventures of a guy making software.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cymbeline.ch\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/cf1f3b3205f4266bf8b68a80fa6b0916","name":"roger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cymbeline.ch\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/33cc08db99ae52beb26ab6fda46e0eb7?s=96&r=g","caption":"roger"},"sameAs":["https:\/\/www.cymbeline.ch"],"url":"https:\/\/cymbeline.ch\/author\/roger\/"}]}},"_links":{"self":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/349"}],"collection":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/comments?post=349"}],"version-history":[{"count":6,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/349\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/posts\/349\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/media?parent=349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/categories?post=349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cymbeline.ch\/wp-json\/wp\/v2\/tags?post=349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}