Closed Martinsos closed 1 year ago
Hi @Martinsos Thank you so much for using dotenv! Have you tried to wrap the value with single quotes?
# .env
JSON='{"a":[1,2,3]}'
I tested locally and it seems to be working fine:
$ dotenv 'echo $JSON' | jq .a
[
1,
2,
3
]
That works perfect! Thanks a lot! Might be worth adding in the docs? What if we have both single and double quotes in our string -> what could we do then?
Hey @Martinsos You can always escape the inner quotes with \'
or \"
depending on the quotes that surround it:
Surround with ''
# .env
JSON='{"a":[1,2,3], "b": "\'asdf\'"}'
Surrounding with ""
# .env
JSON="{\"a\":[1,2,3], \"b\": \"'asdf'\"}"
I'll include a section about this in the README! Thanks for the suggestion. :smile:
So even that works -> ok that is amazing, thanks a lot for being so proactive and helpful!
Hi, do you have any advice how to provide JSON as a value for the env var?
For example, let's say I want to do something like this:
Currently this throws parse error at the first
"
, saying that"
was unexpected and it expected "$(", "${", '$', end of input, end of line, escaped character, or unescaped character.I guess
"
are not allowed in the value? Is this also what other dotenv libraries do, don't allow"
in the value? If so, is there a way to go around this somehow?Thanks a lot!