{"id":60,"date":"2019-04-05T17:57:16","date_gmt":"2019-04-05T08:57:16","guid":{"rendered":"https:\/\/www.earce.biz\/?page_id=60"},"modified":"2022-01-20T01:55:23","modified_gmt":"2022-01-19T16:55:23","slug":"tool-json-to-csv","status":"publish","type":"page","link":"https:\/\/www.earce.biz\/?page_id=60","title":{"rendered":"[Tool] JSON to CSV"},"content":{"rendered":"\n<p class=\"has-text-align-center wp-block-paragraph\">&lt;&lt; This service is not communicating with the server. &gt;&gt;<\/p>\n\n\n\n<script type=\"text\/javascript\">\njQuery().ready(function($){\n\n$(\"#convJ2T\").click(\n  function(e) {\n    var textJSON = $(\"#textJSON\").val();\n    if (textJSON == \"\") {\n      textJSON = $(\"#textJSON\").attr(\"placeholder\");\n    }\n    var jsonObj = JSON.parse(textJSON);\n    if (Array.isArray(jsonObj)==false) {\n      jsonObj = [jsonObj];\n    }\n\n    $('#tabledata').empty();\n    $('#textCSV').val(\"\");\n    if (Array.isArray(jsonObj)) {\n      var tmpkeys = {};\n      for (var idx in jsonObj) {\n        var obj = jsonObj[idx];\n        for (var key in obj) {\n          tmpkeys[key] = key;\n        }\n      }\n      \n      var htmlbuf = \"<tr>\";\n      var csvbuf = \"\";\n      var keys = [];\n      for (var idx in tmpkeys) {\n        keys.push(idx);\n      }\n      keys.sort();\n      for (var idx in keys) {\n        htmlbuf += \"<th nowrap><pre>\" + keys[idx] + \"<\/pre><\/th>\";\n        csvbuf += keys[idx] + \",\";\n      }\n      htmlbuf += \"<\/tr>\";\n      $('#tabledata').append(htmlbuf);\n      csvbuf += \"\\r\\n\";\n      \n      for (var idx in jsonObj) {\n        var obj = jsonObj[idx];\n        \n        var htmlbuf = \"<tr>\";\n        for (var keyIdx in keys) {\n          htmlbuf += \"<td>\" + (obj[keys[keyIdx]]!=null?obj[keys[keyIdx]]:\"\") + \"<\/td>\";\n          csvbuf += (obj[keys[keyIdx]]!=null?obj[keys[keyIdx]]:\"\") + \",\";\n        }\n        htmlbuf += \"<\/tr>\";\n        $('#tabledata').append(htmlbuf);\n        csvbuf += \"\\r\\n\";\n      }\n      $('#textCSV').val(csvbuf);\n    }\n  }\n);\n\n});\n<\/script>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>JSON Data<\/strong><\/p>\n\n\n\n<textarea id=\"textJSON\" rows=\"5\" cols=\"100\" placeholder=\"[{&quot;test&quot;:123},{&quot;test&quot;:456},{&quot;test&quot;:789},{&quot;test2&quot;:987}]\"><\/textarea>\n\n\n\n<div class=\"wp-block-button aligncenter custom-wide-button\">\n<button id=\"convJ2T\" class=\"wp-block-button__link has-background has-vivid-cyan-blue-background-color\">Convert<\/button>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>HTML Output<\/strong><\/p>\n\n\n\n<table id=\"tabledata\"><\/table>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>CSV Output<\/strong><\/p>\n\n\n\n<textarea id=\"textCSV\" rows=\"10\" cols=\"100\"><\/textarea>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt; This service is not communicating with the server. &gt;&gt; JSON Data Convert HTML Output CSV Output<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":35,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-60","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/pages\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.earce.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=60"}],"version-history":[{"count":31,"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/pages\/60\/revisions"}],"predecessor-version":[{"id":2795,"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/pages\/60\/revisions\/2795"}],"up":[{"embeddable":true,"href":"https:\/\/www.earce.biz\/index.php?rest_route=\/wp\/v2\/pages\/35"}],"wp:attachment":[{"href":"https:\/\/www.earce.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}