Nested JSON objects fail to parse.
Reproducible Code
require "json"
valid_json = %({"foo": "{\"bar\":\"baz\"}"})
JSON.parse(valid_json) # => Unexpected char 'b' at 1:12 (JSON::ParseException)
Crystal 0.31.1
This also applies for mapping and serialisable.
https://carc.in/#/r/7wen
https://carc.in/#/r/7weq
https://carc.in/#/r/7weo
Not a bug.
Your example is not a nested JSON. The nested JSON is this:
valid_json = {foo: {bar: "baz" } }.to_json
p! valid_json # => "{\"foo\":{\"bar\":\"baz\"}}"
p! JSON.parse(valid_json) # => {"foo" => {"bar" => "baz"}}
If you want a string instead inside a foo key you are missing some escaping.
For a literal \ you need to write \\, even inside %()
Most helpful comment
For a literal
\you need to write\\, even inside%()https://carc.in/#/r/7wfv