Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define string vs base32 vs base64 #20

Closed
DonaldTsang opened this issue Nov 29, 2019 · 15 comments
Closed

Define string vs base32 vs base64 #20

DonaldTsang opened this issue Nov 29, 2019 · 15 comments
Assignees

Comments

@DonaldTsang
Copy link

Might be a good idea to have a YAML !!str to !!binary (binary as in base64) equivalent.
Base64 should be standardized to be HTML and JSON safe, either RFC 4648 §5 (- and _) or, next best option, RFC 4648 + and / (might cause issues with comments if there are double slash in the data).
base32 should be either Crockford's, or second best, RFC 4648 (more confusable characters).

@jordanbtucker
Copy link
Member

What benefit does this have over storing Base64 encoded data in a string?

@DonaldTsang
Copy link
Author

@jordanbtucker it IS base64 in a string, just that we need some kind of "flag" or "header" to note is as such.

@DonaldTsang
Copy link
Author

DonaldTsang commented Nov 30, 2019

Just a note: We are not even considering

  • 32-bit base85 0.99 (standardized "somewhat")
  • 128-bit base69 0.95 (more efficient than base64)
  • 256-bit base76 0.97 (more efficient than base64)

since these are more niche formats for packing more data than base64

@DonaldTsang DonaldTsang changed the title Define hexadecimal vs base32 vs base64 Define string vs base32 vs base64 Nov 30, 2019
@jordanbtucker
Copy link
Member

How would you implement this in an ES5 compatible way?

@DonaldTsang
Copy link
Author

@jordanbtucker perhaps instead of "string" maybe ["format", "string"] ? I think "octet-stream" is a common flag as well?

@jordanbtucker
Copy link
Member

I still don't understand. Can you give a full example of a JSON5 document that uses your proposed feature?

@DonaldTsang
Copy link
Author

Here is an example in standard JSON with base64 encoding

{
    "mimetype" : "application/octet-stream",
    "metadata" : [ ],
    "value" :   "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
    IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
    dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
    dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
    ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",
}

Surly there could be a way for JSON5 to trim the fat and make base64 object wrappers "shorter"?

@jordanbtucker
Copy link
Member

Yes, there could be a way for JSON5 to make this shorter, but why? Why isn't your example good enough?

@DonaldTsang
Copy link
Author

Too many characters or too clunky (my first thought)? if I can design my syntax then s"base64string" or something where the first s is the flag of the string? And the same can be applied to different encodings or something? Maybe it is too much complexity?

@jordanbtucker
Copy link
Member

This breaks ES5 compatibility.

@DonaldTsang
Copy link
Author

What would be the most lightweight yet compatible way of labeling a string as base64 or some other common encoding?

@jordanbtucker
Copy link
Member

You could encode the string like this:

'base64:SGVsbG8sIFdvcmxkIQ=='

Then use a recover function to parse it.

@DonaldTsang
Copy link
Author

'b64:SGVsbG8sIFdvcmxkIQ==' looks even slimmer TBH, maybe we can write other compatibility documents outside the JSON5 standard (but by the JSON5 committee) to aid in designing API recommendations?

@zamicol
Copy link

zamicol commented May 16, 2022

JSON5 supports Hex in "0x" and "0X" forms, which is awesome:
https://github.com/json5/json5/blob/4cf57da675f55c619f959132eb58a5683ca4a9c7/lib/parse.js#L416

I wanted to confirm and explicitly state that JSON5 will never support base64 since it would break ES5 compatibility.

(I would not be in favor, just double checking to make sure.)

Thanks for all you do Jordan.

@jordanbtucker
Copy link
Member

@zamicol I can confirm that there are no plans to include support for a Base64 literal value in JSON5. Please see #35 for a discussion on the recommended ways to represent binary data in a JSON5 document.

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

No branches or pull requests

3 participants