A Case for JSON6

Just a required follow up for the previous post: JSON5 sucks too, like any other possible format. Just look at this:

{
    certificate: "\
-----BEGIN PRIVATE KEY-----\n\
MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAt6wGEsfdarMo9KET\n\
sNv9gpBWkGfhIq3/Jhr14+3d8TXprmTk/XWReo5DA3+SbB7ebF3xUtN/4K5lUkcG\n\
1AbdywIDAQABAkBuMbfnFqAhvuFoeydMKYAcECrPMnOhEdENdIlnuTM53kBf18f/\n\
KaWRWv8ViuZ31GpArY8cBzj0YG30vE49Il8ZAiEA7PpotzcpjNcMKnwEBm3q0c6H\n\
3RRZD6i32Q/vXcQBeB0CIQDGaj4BJ/fuqiHvKzetfjhpOD+sYr3VDgEyjTcojhzZ\n\
BwIgTBRYafmbrUuc7EbERAwlxxW3KJLPxOc1nsou3rt+fUECIQCjBGUfJAyDDUtG\n\
KpbbN0n3wRwncRUQuCnps7Zu3pv6/wIhAIIcKty7O0T7auctlpMSdyw6vp0w818x\n\
namFjg3cbBs4\n\
-----END PRIVATE KEY-----\n"
}

Notice these "\n\". Arguably such stuff does not belong in configs, but it's not always possible to avoid it. Just to compare, let's look at the others. TOML wouldn't allow indentation too but at least it is structured in such a way so you can avoid indentation entirely:

certificate = '''
-----BEGIN PRIVATE KEY-----
MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAt6wGEsfdarMo9KET
sNv9gpBWkGfhIq3/Jhr14+3d8TXprmTk/XWReo5DA3+SbB7ebF3xUtN/4K5lUkcG
1AbdywIDAQABAkBuMbfnFqAhvuFoeydMKYAcECrPMnOhEdENdIlnuTM53kBf18f/
KaWRWv8ViuZ31GpArY8cBzj0YG30vE49Il8ZAiEA7PpotzcpjNcMKnwEBm3q0c6H
3RRZD6i32Q/vXcQBeB0CIQDGaj4BJ/fuqiHvKzetfjhpOD+sYr3VDgEyjTcojhzZ
BwIgTBRYafmbrUuc7EbERAwlxxW3KJLPxOc1nsou3rt+fUECIQCjBGUfJAyDDUtG
KpbbN0n3wRwncRUQuCnps7Zu3pv6/wIhAIIcKty7O0T7auctlpMSdyw6vp0w818x
namFjg3cbBs4
-----END PRIVATE KEY-----
'''

YAML shines. In all that string mess, there is a perfect solution for this specific use case:

certificate: |
    -----BEGIN PRIVATE KEY-----
    MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAt6wGEsfdarMo9KET
    sNv9gpBWkGfhIq3/Jhr14+3d8TXprmTk/XWReo5DA3+SbB7ebF3xUtN/4K5lUkcG
    1AbdywIDAQABAkBuMbfnFqAhvuFoeydMKYAcECrPMnOhEdENdIlnuTM53kBf18f/
    KaWRWv8ViuZ31GpArY8cBzj0YG30vE49Il8ZAiEA7PpotzcpjNcMKnwEBm3q0c6H
    3RRZD6i32Q/vXcQBeB0CIQDGaj4BJ/fuqiHvKzetfjhpOD+sYr3VDgEyjTcojhzZ
    BwIgTBRYafmbrUuc7EbERAwlxxW3KJLPxOc1nsou3rt+fUECIQCjBGUfJAyDDUtG
    KpbbN0n3wRwncRUQuCnps7Zu3pv6/wIhAIIcKty7O0T7auctlpMSdyw6vp0w818x
    namFjg3cbBs4
    -----END PRIVATE KEY-----

So JSON6 should bring it at least to the TOML level:

{
    certificate: `
-----BEGIN PRIVATE KEY-----
MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAt6wGEsfdarMo9KET
sNv9gpBWkGfhIq3/Jhr14+3d8TXprmTk/XWReo5DA3+SbB7ebF3xUtN/4K5lUkcG
1AbdywIDAQABAkBuMbfnFqAhvuFoeydMKYAcECrPMnOhEdENdIlnuTM53kBf18f/
KaWRWv8ViuZ31GpArY8cBzj0YG30vE49Il8ZAiEA7PpotzcpjNcMKnwEBm3q0c6H
3RRZD6i32Q/vXcQBeB0CIQDGaj4BJ/fuqiHvKzetfjhpOD+sYr3VDgEyjTcojhzZ
BwIgTBRYafmbrUuc7EbERAwlxxW3KJLPxOc1nsou3rt+fUECIQCjBGUfJAyDDUtG
KpbbN0n3wRwncRUQuCnps7Zu3pv6/wIhAIIcKty7O0T7auctlpMSdyw6vp0w818x
namFjg3cbBs4
-----END PRIVATE KEY-----`,
}

Still, I don't believe that all planned features are good there, JSON6 aggressively ditches simplicity for syntax sugar.

Needless to say, even the top file here is better than raw JSON, where multiline representation for strings is not possible at all.

Comments

Comments powered by Disqus