title: parse a PEM certificate into JSON
body: <p>I've got a PEM certificate and I'm using <code>openssl</code> to view its content. Is it possible to parse the output into a JSON format? Maybe there's a Java library or Bash script that can do this?</p>
  
  <p>command: <code>$ openssl x509 -in sample.cer -noout -text</code></p>
  
  <p>output:</p>
  
  <pre><code>Certificate:
      Data:
          Version: 3 (0x2)
          Serial Number:
              af:69:46:11:10:bd:82:88
          Signature Algorithm: sha1WithRSAEncryption
          Issuer: C=US, ST=Texas, L=Plano, O=2xoffice, OU=Architecture, CN=Joshua Davies/emailAddress=joshua.davies.tx@gmail.com
          Validity
              Not Before: May 21 21:49:10 2014 GMT
              Not After : Jun 20 21:49:10 2014 GMT
          Subject: C=US, ST=Texas, L=Plano, O=2xoffice, OU=Architecture, CN=Joshua Davies/emailAddress=joshua.davies.tx@gmail.com
          Subject Public Key Info:
              Public Key Algorithm: rsaEncryption
              RSA Public Key: (512 bit)
                  Modulus (512 bit):
                      00:b7:38:0d:e0:ab:37:18:a7:26:95:9d:9e:6f:a2:
                      69:b1:b9:ee:b3:7f:29:04:fb:f0:94:b3:d0:d5:55:
                      c0:d8:6b:14:7f:94:13:3c:d9:a2:61:bf:ba:3f:0a:
                      44:37:dc:18:b5:23:c7:ee:96:2d:7c:d8:92:04:48:
                      74:f8:c6:46:a5
                  Exponent: 65537 (0x10001)
          X509v3 extensions:
              X509v3 Subject Key Identifier: 
                  1A:A5:C9:C8:36:EA:7D:FA:B4:DF:A4:9C:11:F9:C1:BE:78:C4:42:DD
              X509v3 Authority Key Identifier: 
                  keyid:1A:A5:C9:C8:36:EA:7D:FA:B4:DF:A4:9C:11:F9:C1:BE:78:C4:42:DD
                  DirName:/C=US/ST=Texas/L=Plano/O=2xoffice/OU=Architecture/CN=Joshua Davies/emailAddress=joshua.davies.tx@gmail.com
                  serial:AF:69:46:11:10:BD:82:88
  
              X509v3 Basic Constraints: 
                  CA:TRUE
      Signature Algorithm: sha1WithRSAEncryption
          56:32:44:76:86:8c:08:92:74:71:0e:ac:a6:7d:ba:1d:7c:d3:
          b6:74:ef:27:7a:5e:53:21:fc:8e:eb:26:58:e0:6e:4f:5c:01:
          f1:40:ca:0a:e9:d2:0e:00:60:ae:1f:f6:a5:a4:4c:47:fb:e0:
          68:7f:25:63:ab:60:38:0f:74:94
  </code></pre>