Since this is possible. I am now 100% convinced JSON.parse
could statically type values. And with the power of macros, remove the need to use method invocation calls everywhere (to_i, as_s, etc).
If you can do it with CSV data, there is no reason it cannot be done with JSON data.
In @bcardiff’s first example, there is literally just alias TypedRow = {name: String, min_value: Int32, max_value: Int32, mod_type: String}
used. And boom, no need for method invocations. Same should be possible for JSON.parse
.
And especially for recursive data so you don’t need to maintain a mapping of the structure. Obviously, crystal is statically typed, so it’s not a bad thing, but we’re talking about the context of JSON.parse
, and this makes that process so easy already, it should be even better (remove need for method invocation calls). This will allow JSON.parse
take advantage of statically typed values.