JSON: Difference between revisions

Content added Content deleted
Line 965: Line 965:


=={{header|Crystal}}==
=={{header|Crystal}}==
Before 1.0.0:
<lang Ruby>
<lang Ruby>
require "json"
require "json_mapping"


class Foo
class Foo
Line 982: Line 983:
</lang>
</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"]
<pre>1 ["a", "b"]
{"num":1,"array":["a","b"]}</pre>
{"num":1,"array":["a","b"]}</pre>