var response = request.execute
if response isa CurlResponseSuccess then
- var obj = response.body_str.json_to_nit_object
+ var obj = response.body_str.parse_json
if obj isa JsonObject then
if obj.keys.has("message") then
print "Message from Github API: {obj["message"] or else ""}"
redef class Text
# Parse `self` to obtain a `JsonValue`
- fun to_json_value: JsonValue
- do
- var value = json_to_nit_object
+ fun to_json_value: JsonValue do
+ var value = parse_json
return new JsonValue(value)
end
end
# Static interface to get Nit objects from a Json string.
#
-# `String::json_to_nit_object` returns an equivalent Nit object from
+# `Text::parse_json` returns an equivalent Nit object from
# the Json source. This object can then be type checked by the usual
# languages features (`isa` and `as`).
module static
return buffer.write_to_string
end
- fun json_to_nit_object: nullable Jsonable do
+ fun parse_json: nullable Jsonable do
var lexer = new Lexer_json(to_s)
var parser = new Parser_json
var tokens = lexer.lex
init(text: Text)
do
- var root = text.json_to_nit_object
+ var root = text.parse_json
if root isa JsonObject then path.add(root)
self.root = root
end
var d = "\{ \"face with tears of joy\" : \"\\uD83D\\uDE02\" \}"
for s in [a, b, c, d] do
- var obj = s.json_to_nit_object
+ var obj = s.parse_json
print "# Json: {s}"
print "# Nit: {obj or else "<null>"}"
end