Replies: 1 comment
-
Just use a raw string literal https://en.cppreference.com/w/cpp/language/string_literal:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, you can construct a simple
json
object from a literal JSON string like ...json j = "{\"happy\": \"day\", \"pi\": 3.141}"_json;
... but it isn't pretty with all the embedded backslashes.
What about allowing embedded apostrophe characters (
'
,U+0027
) in a literal JSON string as a stand-in for quotation marks ("
,U+0022
), making this source functionally equivalent to the one above ...json j = "{'happy': 'day, 'pi': 3.141}"_jsons;
... a lot easier to type AND to read1
_jsons
user-defined literal suffix would work just like_json
, except treating every occurrence of an apostrophe ('
) as a stand-in for a quotation mark ("
).'
) embedded in JSON content['Do', 'Don't']
, but I bet that it would cope with 99% of literal JSON strings in the wild, and you can always fall back to using_json
as before/[a-zA-Z0-9_]'[a-zA-Z0-9_])/
) should be treated as a literal (embedded) apostrophy, which would handle the vast majority cases, but not something like['Charles' crown']
'
➡️"
) substitutions in places where a"
would be permitted in well formed JSON, but that would require a LOT more work implementing and testingI would like to hear arguments why this would NOT be a good idea to implement
Footnotes
Note the
_jsons
(rather than_json
) user-defined literal suffix ↩Beta Was this translation helpful? Give feedback.
All reactions