{"id":1401,"date":"2026-02-10T09:35:57","date_gmt":"2026-02-10T09:35:57","guid":{"rendered":"https:\/\/monkey.ploogie.co.uk\/?page_id=1401"},"modified":"2026-02-10T09:35:57","modified_gmt":"2026-02-10T09:35:57","slug":"mwnci-certtojson-function","status":"publish","type":"page","link":"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-certtojson-function\/","title":{"rendered":"Mwnci certtojson() Function"},"content":{"rendered":"<h2>Syntax<\/h2>\n<p>certtojson<strong>(<em>string<\/em>)<\/strong><\/p>\n<h2>Description<\/h2>\n<p>The <i>certtojson()<\/i> function returns certificated data in JSON format, which is converted to object data format for use.<br \/>\nIf the file cannot be read, or unable to retrieve the information and empty array is returned.<\/p>\n<h2>Example<\/h2>\n<p>We have the file certycert.crt<\/p>\n<pre>\r\n-----BEGIN CERTIFICATE-----\r\nMIIFGDCCBACgAwIBAgISBhm0+5UqWrgNw1W0ToFoxxpGMA0GCSqGSIb3DQEBCwUA\r\nMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQD\r\nEwNSMTMwHhcNMjYwMTExMDAxOTIxWhcNMjYwNDExMDAxOTIwWjAgMR4wHAYDVQQD\r\nExV3d3ctZmFzdGx5LmRlYmlhbi5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw\r\nggEKAoIBAQDbWcvoUOz6+9wvEtvV4wlk3CLrjDawvqaBJoS4SFfDkL0Q3bIRemCB\r\nkOYG9Z0UfdiWrUm2v+D69fhdYen727ofk9s4545QEnvK5DxYmtYM\/T+JTEUVuxIa\r\nehirGpYMcI9LBtQa6+uRa6NiCr6tUXF9UOXj1sOoEnRTuhFOL+r8A\/BCaRa\/yRDd\r\n1BeYzoLsY66Zp7Uy0qJDpeinhWFZbm8+DJmeyBpLAPKX\/eUH7aSzTykFn81k0rLd\r\n\/kk\/y5HnE1PtmRyDNqLN1Cn996a\/hRM3X\/LTcsZL2TlWqNfEazdolG8uI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y2fksQolZLfyRk2DIiqFcQeQUfFq5MiQAflnKt2uoqpECOw3QS\r\nr8510TBjG7OCMI25iDWYgS5mvuE283oFt6+jHDnJi0R2IQHI9I00f8iapaQKeJJz\r\ncHM7QwpLQNjoXewDP4CJVtgv23bVs3HAHKmHv8SQS8BOKusMGB\/EAFmLqP2sDVDS\r\nDSqbRkbYBKgr\/6ah\r\n-----END CERTIFICATE-----\r\n<\/pre>\n<pre>include(\"cert\")\r\nCertData=cat(\"certycert.crt\")\r\nJson=certtojson(CertData)\r\nprintln(Json)\r\nprintln(\"\\n\")\r\nprintln(\"Pretty print:\")\r\nprintln(pjson(Json))\r\nprintln(\"\\n\", Json[0][\"certificate\"][\"validity\"])\r\n\r\n[{\"certificate\": {\"validity\": {\"not_before\": 1768090761, \"not_after\": 1775866760, \"not_before_iso\": \"Jan 11 00:19:21 2026 GMT\", \"not_after_iso\": \"Apr 11 00:19:20 2026 GMT\"}, \"subject\": {\"common_name\": \"www-fastly.debian.org\"}, \"signature_algorithm\": {\"algorithm\": \"sha256 RSA\"}, \"alternate_names\": [\"debian.org\", \"www-fastly.debian.org\"], \"version\": \"v3\", \"serial_number\": \"06:19:b4:fb:95:2a:5a:b8:0d:c3:55:b4:4e:81:68:c7:1a:46\", \"signature\": {\"algorithm\": \"sha256 RSA\"}, \"issuer\": {\"organization_name\": \"Let's Encrypt\", \"country_name\": \"US\", \"common_name\": \"R13\"}}}]\r\n\r\n\r\nPretty print:\r\n[\r\n  {\r\n    \"certificate\": {\r\n      \"validity\": {\r\n        \"not_before_iso\": \"Jan 11 00:19:21 2026 GMT\",\r\n        \"not_after_iso\": \"Apr 11 00:19:20 2026 GMT\",\r\n        \"not_before\": 1768090761,\r\n        \"not_after\": 1775866760\r\n      },\r\n      \"subject\": {\r\n        \"common_name\": \"www-fastly.debian.org\"\r\n      },\r\n      \"signature_algorithm\": {\r\n        \"algorithm\": \"sha256 RSA\"\r\n      },\r\n      \"alternate_names\": [\r\n        \"debian.org\",\r\n        \"www-fastly.debian.org\"\r\n      ],\r\n      \"version\": \"v3\",\r\n      \"serial_number\": \"06:19:b4:fb:95:2a:5a:b8:0d:c3:55:b4:4e:81:68:c7:1a:46\",\r\n      \"signature\": {\r\n        \"algorithm\": \"sha256 RSA\"\r\n      },\r\n      \"issuer\": {\r\n        \"country_name\": \"US\",\r\n        \"organization_name\": \"Let's Encrypt\",\r\n        \"common_name\": \"R13\"\r\n      }\r\n    }\r\n  }\r\n]\r\n\r\n{\"not_after\": 1775866760, \"not_before_iso\": \"Jan 11 00:19:21 2026 GMT\", \"not_after_iso\": \"Apr 11 00:19:20 2026 GMT\", \"not_before\": 1768090761}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Syntax certtojson(string) Description The certtojson() function returns certificated data in JSON format, which is converted to object data format for use. If the file cannot be read, or unable to retrieve the information and empty array is returned. Example We have the file certycert.crt &#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211; MIIFGDCCBACgAwIBAgISBhm0+5UqWrgNw1W0ToFoxxpGMA0GCSqGSIb3DQEBCwUA MDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQwwCgYDVQQD EwNSMTMwHhcNMjYwMTExMDAxOTIxWhcNMjYwNDExMDAxOTIwWjAgMR4wHAYDVQQD ExV3d3ctZmFzdGx5LmRlYmlhbi5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw ggEKAoIBAQDbWcvoUOz6+9wvEtvV4wlk3CLrjDawvqaBJoS4SFfDkL0Q3bIRemCB kOYG9Z0UfdiWrUm2v+D69fhdYen727ofk9s4545QEnvK5DxYmtYM\/T+JTEUVuxIa ehirGpYMcI9LBtQa6+uRa6NiCr6tUXF9UOXj1sOoEnRTuhFOL+r8A\/BCaRa\/yRDd 1BeYzoLsY66Zp7Uy0qJDpeinhWFZbm8+DJmeyBpLAPKX\/eUH7aSzTykFn81k0rLd \/kk\/y5HnE1PtmRyDNqLN1Cn996a\/hRM3X\/LTcsZL2TlWqNfEazdolG8uIenbNrxL &hellip; <a href=\"https:\/\/monkey.ploogie.co.uk\/index.php\/mwnci-certtojson-function\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mwnci certtojson() Function&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1401","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1401"}],"version-history":[{"count":2,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1401\/revisions"}],"predecessor-version":[{"id":1403,"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/1401\/revisions\/1403"}],"wp:attachment":[{"href":"https:\/\/monkey.ploogie.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}