Reputation: 14918
I have a JSON string literal as below, needing many backslashes.
"{\"key1\":\"value1\",\"key2\":\"value2\"}"
Is there a way to avoid writing these backslashes? For example in Python we can use single quotation marks to delimit a string.
Upvotes: 0
Views: 1672
Reputation: 13572
Could you store the literal as a dict and convert to json at runtime? That way it remains clean and easier to read:
q)jstr:.j.j`key1`key2!("value1";"value2")
q)jstr~"{\"key1\":\"value1\",\"key2\":\"value2\"}"
1b
To answer your question - no, there's no way to avoid escaping in strings other than casting from some other form or running a lambda to generate the string. The built-in function .Q.s1
could help but I don't think an approach using that would be any better than the .j.j
approach above
q).Q.s1"abc"
"\"abc\""
Upvotes: 3