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
Impossible to get string with single backslash in output #679
Comments
+10 for this. How come single slashes are not allowed in a JSON? |
The thing is that in JSON Similarly JSON strings Python agrees btw:
Escaping Please let me know if that answers your question. |
@sbarzowski, though it's a comprehensive answer, I suggest you pay more attention when reading the question.
In other words, escaping the escaping backslash just produces two backslashes. Therefore, the last bit of "example output" you've provided is not how jsonnet handles this. Instead, it actually produces
|
Did you actually run it in Python? This was directly copy&pasted from Python shell. Here you can see it yourself: https://www.onlinegdb.com/S1g978ilH.
Yes, because it also needs to be escaped in the output JSON. I'm arguing that it is the correct behavior. And that trying to get JSON output For completeness I'll add that you can use the "raw string" mode ( |
In other words if you want it to be loaded with a single backslash you need these two backslashes in JSON. E.g.:
With a single backslash it won't work as expected (it will be interpreted as escaped
|
I'm going to assume that it's all clear now after my last explanation. If it's not, feel free to reopen. |
Just came here to add that in YAML, you can specify a single character string containing a backslash as either: \ or "\\" In JSON, only the latter is supported. When Jsonnet generates YAML with |
Oh and just for completeness -- the various ways of specifying it in Jsonnet: [
"\\",
'\\',
@"\",
@'\',
// Note, this last one also adds a \n, see #289
|||
\
|||,
] |
I am using jsonnet to write configurations for drone ci. Drone uses jsonnet to generate yaml file and use it as instruction for CI/CD.
For my needs I want to have the following output:
I tried the following jsonnet script:
And it gave me:
Then I tried:
It gave me:
I did not find a way to achieve what I want. Seems to me it's currently impossible.
P.S. I am using the latest version of jsonnet
The text was updated successfully, but these errors were encountered: