Reputation: 681
I recently got back into crystal and I noticed some breaking changes concerning JSON behaviour in 0.25.0.
Previously, when I had a variable of type JSON::Type
, I could simply store a string in it
a : JSON::Type
a = "some string"
this is no longer possible after changing the variable to JSON::Any
, resulting in an error: type must be JSON::Any, not String
However, calling .to_json
or as(JSON::Any)
on the string also does not work because the returned value is also of class String
.
puts typeof("Hello".to_json) => String
puts typeof("Hello".as(JSON::Any)) => String
Is this intended behaviour? How do I now store strings in json?
Also, locally, for JSON.parse("some string")
I get a JSON::ParseException
, while it works online...
https://play.crystal-lang.org/#/r/4y49
Upvotes: 0
Views: 229