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

Added support for JSON env variables through the "json" feature. Issue #84 #130

Closed
wants to merge 1 commit into from

Conversation

ZocoLini
Copy link

@ZocoLini ZocoLini commented Sep 15, 2024

Description:
Using the "json" feature the code will validate if the environment variables are a valid JSON string using serde_json when the input starts with '{' and ends with '}'. Additionally, one test has been added to ensure that this validation works correctly with JSON variables and other types of environment variables in the same file.

Related Issue:
Closes #84

@allan2
Copy link
Owner

allan2 commented Sep 15, 2024

Thanks for the PR.

dotenvy is responsible for loading environment variables. Validating a specific format is outside the scope of this library.

My comment on #84 meant that the behaviour of escaping braces should be clearly defined. I have not looked closely at that issue yet. I'm sorry if it seemed to suggest that I would welcome specific format support.

@allan2 allan2 closed this Sep 17, 2024
@ZocoLini
Copy link
Author

There is no need for escaping braces, the JSON format doesn't start with "${" so the first '{' is pushed into the output string. The thing is, the parse_value() function, after pushing '{' finds a blank space and expecting_end becomes true and then, in the next loop iteration, the function returns an Err. In fact, the environment variable FOO={} is valid for the actual parser but FOO={ } isn't.

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.

Storing a JSON object as an env value leads to a parsing error
2 participants