In BASH, I can store JSON into an environment variable via jq:
export FOO=$(curl ... | jq -Rs)
Now, if I load that into python:
bar=os.environ["FOO"]
bar will have something like: {\\"this\\":\\"that\\"}, which is a problem when loading with json:
json.loads(bar) # error
I have tried a few things including repr, rf'{os.environ["FOO"]}' and so on, but there doesn't seem to be an internally managed way to drop the extra slashes.
How do I drop the extra slashes via string functions? I'd prefer not to simply replace them with a single slash, as I might have to touch that code again sometime in the future.
Add the
-rflag to output as raw text fromjq. Here is an example using echo that gives the escaped results:But adding
-rgives a result that is still in JSON format without all of the escaped quotes:Which is parseable by Python.