Skip to content

Conversation

@ansel1
Copy link

@ansel1 ansel1 commented Jun 25, 2025

Adds support in the parser for treating JSON values specially. If the entire value is enclosed in curly braces or brackets, treat the value as a JSON string. Treat quotes and spaces inside the JSON value as literals.

Adds support in the parser for treating JSON values specially.  If the entire value is enclosed in curly braces or brackets, treat the value as a JSON string.  Treat quotes and spaces inside the JSON value as literals.
@allan2
Copy link
Owner

allan2 commented Jun 26, 2025

Hi @ansel1, thank you for submitting a PR.

I don't think the parser should care about the format of the value. It doesn't matter if the value is JSON, TOML, valid to the spec, or invalid. We just want to be able to parse a value that contains double quotes, like a typical JSON, without escaping.

I added a comment on the issue. I'm happy to hear your thoughts.

@ansel1
Copy link
Author

ansel1 commented Jun 26, 2025

I tend to agree, but I'm not sure how else other libraries would have implemented this. The rules inside probable JSON structures are just so different than the normal rules: spaces, double quotes and single quotes should be treated as literals, but substitution should still work (debatable I guess), and therefore slash-escape still needs to work...it's like a universe with different rules of physics.

Arguably, even the substitution and escape semantics should be disabled, and the entire value should be treated like a strong quote, since dotenv's escape character collides with JSON's.

That's why I put in the logic to only activate this mode when the entire value looks like a JSON object or array: to limit the blast radius of unintended side effects.

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

Successfully merging this pull request may close these issues.

2 participants