Skip to content

Instantly share code, notes, and snippets.

@thomaslarsen
Last active October 25, 2024 18:08
Show Gist options
  • Save thomaslarsen/bc742bcd958896458d8006bdadf7d102 to your computer and use it in GitHub Desktop.
Save thomaslarsen/bc742bcd958896458d8006bdadf7d102 to your computer and use it in GitHub Desktop.
Convert PEM certificate to JSON format
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' cert-name.pem
@jayachandrareddym
Copy link

"---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20191003"
AAAAB3NzaC1yc2EAAAABJQAAAQEAyVL47bCG41zJu2tdWEwPQwrzb+ettT+o5zl2
2ERrlx5oV2UQ4msjPZN5cWtHeeNsGBpG9J/+vbZF8uEYbVY640fRI7YjmIlNDUp6
a41IVQvHS15uyKJx6kfFMubkdjzrlzmMAYHfHp1B32bnSjgkkM87L+p/C4z7RaK4
CLiUzWGTyhYOmRuo6zIFUVbpi3Fo/HOIiDq6o3PFd9tkdrzgGDtIZsDA77+6QQpw
y4PwjxfSl53We1YiQ4+pwWfwBoSr6WnuSEropxeBnNpKXnGcij6yrHGppZCF/Qjx
c65YvrIxrVVER+gN/AuX24cRG0HjsUP2dcsTBhOJfBE3Z8GI7Q==
---- END SSH2 PUBLIC KEY ----
"

@jrab66
Copy link

jrab66 commented Mar 16, 2020

And to do the backward process :v ?

@benaryorg
Copy link

If you need a more modern version of this you can use jq to do all sorts of magic with JSON.
In any case you could run jq -sR . $any_file to convert the entire file to JSON.

Sorry, just happened to stumble on this and thought jq might help someone.

@fabiojmendes
Copy link

It definitely helped me! Thanks @benaryorg

@steelysteel
Copy link

Helped me as well. Thanks @benaryorg

@ashishpatel1992
Copy link

Thanks @benaryorg . Really appreciate your solution.

@mr-molloy
Copy link

This is amazing. Much appreciated 😁

@ldnicolasmay
Copy link

If you need a more modern version of this you can use jq to do all sorts of magic with JSON. In any case you could run jq -sR . $any_file to convert the entire file to JSON.

Sorry, just happened to stumble on this and thought jq might help someone.

Yep... jq definitely comes in handy for this. Thanks @benaryorg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment