SSL Certificate to JSON

escaping, json, ssl-certificate, unix

Solution

The problem was indeed related to the white spaces and line breaks.

Here is what worked for me:

Copied the certificate into a one line text field. Not very elegant but it's a quick way to make a one line string out of it. Most text editors can do that too, i guess.

Replaced the line breaks (now white spaces) with "\n". Do not replace the white spaces between those phrases `-----BEGIN RSA PRIVATE KEY-----` they can stay as they are.

Example:

{
"key": "-----BEGIN RSA PRIVATE KEY-----\njlQvt9WdR9Vpg3WQT5+C3HU17bUOwvhp/r0+viMcBUCRW85UqI2BJJKTi1IwQQ4c\ntyTrhYJYOP+A6JXt5BzDzZy/B7tjEMDBosPiwH2m4MaP+6wTbi1qR1pFDL3fXYDr\n"
}

Problem

I need to send a SSL Certificate as a string via JSON to my server. On the server I need to reconstruct the JSON string to a valid certificate. My problems are the spaces and line brakes in the certificate. How can I preserve the correct format of the certificate?

Original source