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

encoding #1

Open
gonzus opened this issue Oct 7, 2020 · 1 comment
Open

encoding #1

gonzus opened this issue Oct 7, 2020 · 1 comment

Comments

@gonzus
Copy link

gonzus commented Oct 7, 2020

Is there any reason why there is no support for encode?

@jforget
Copy link

jforget commented Sep 10, 2024

Direct answer

Use JSON::PP::encode_json. Module JSON::PP is a prereq for JSON5,
so you do not need to install it, you do not need to add a use JSON::PP
into you program. Example:

use JSON5;
my %chem_elem = (H => 1, He => 2, Li => 3);
print JSON::PP::encode_json(\%chem_elem), "\n";

Answer about the context

As mentioned in JSON5.org, JSON5 is aimed at
human-written files, such as config files. In another website (sorry,
I do not remember which website), I have read that JSON v4 is still
relevant for machine-written files and that any program dumping data
as JSON should use the stricter v4 version.

See also this comparison.

Module JSON5 deals with human-to-machine communication, not
machine-to-machine or machine-to-human communication. So the module
does not support encode. It is lighter, shorter and it follows the
KISS principle (keep it simple, stupid) and Occam's Razor (Entities
must not be multiplied beyond necessity).

J Forget

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

No branches or pull requests

2 participants