json: Add `JsonValue.json_type`.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 17 Nov 2014 20:24:55 +0000 (15:24 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Mon, 17 Nov 2014 20:24:55 +0000 (15:24 -0500)
Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/json/dynamic.nit

index e39e2d6..199b816 100644 (file)
@@ -214,6 +214,18 @@ class JsonValue
                end
                return new JsonValue(value)
        end
+
+       # Return a human-readable description of the type.
+       fun json_type: String do
+               if is_array then return "array"
+               if is_bool then return "bool"
+               if is_float then return "float"
+               if is_int then return "int"
+               if is_null then return "null"
+               if is_map then return "map"
+               if is_string then return "string"
+               return "undefined"
+       end
 end
 
 redef class Text