Jump to content

JSON: Difference between revisions

308 bytes added ,  3 years ago
Line 965:
 
=={{header|Crystal}}==
Before 1.0.0:
<lang Ruby>
require "jsonjson_mapping"
 
class Foo
Line 982 ⟶ 983:
</lang>
 
After 1.0.0:
<lang Ruby>
require "json"
 
class Foo
include JSON::Serializable
property num : Int64
property array : Array(String)
end
 
def json
foo = Foo.from_json(%({"num": 1, "array": ["a", "b"]}))
puts("#{foo.num} #{foo.array}")
puts(foo.to_json)
end
</lang>
 
Output:
<pre>1 ["a", "b"]
{"num":1,"array":["a","b"]}</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.