feature -- Conversion
non_sep_json_o (a_json_o: separate JSON_OBJECT): JSON_OBJECT
do
check
attached {JSON_OBJECT} non_sep_json_value (a_json_o) as l_res
then
Result := l_res
end
ensure
instance_free: Class
end
non_sep_json_value (a_json_v: separate JSON_VALUE): JSON_VALUE
local
l_json_s: JSON_STRING
l_s: STRING
do
-- - JSON_ARRAY: no assertion
-- - JSON_BOOLEAN: no assertion
-- - JSON_NULL: no assertion
-- - JSON_NUMBER: no assertion
-- - JSON_OBJECT: no assertion
-- - JSON_STRING: no assertion
if attached {separate JSON_ARRAY} a_json_v as l_json then
create {JSON_ARRAY} Result.make (l_json.count)
check
attached {JSON_ARRAY} Result as l_res
then
across
l_json as l_item
loop
check
attached {JSON_VALUE} non_sep_json_value (l_item.item) as l_non_sep_json_value
then
l_res.extend (l_non_sep_json_value)
end
end
end
elseif attached {separate JSON_BOOLEAN} a_json_v as l_json then
create {JSON_BOOLEAN} Result.make (l_json.item)
elseif attached {separate JSON_STRING} a_json_v as l_json then
create l_s.make_from_separate (l_json.item)
create {JSON_STRING} Result.make_from_string (l_s)
elseif attached {separate JSON_NULL} a_json_v as l_json then
create {JSON_NULL} Result
elseif attached {separate JSON_NUMBER} a_json_v as l_json then
if l_json.is_integer then
create {JSON_NUMBER} Result.make_integer (l_json.integer_64_item)
elseif l_json.is_real then
create {JSON_NUMBER} Result.make_real (l_json.real_64_item)
elseif l_json.is_natural then
create {JSON_NUMBER} Result.make_natural (l_json.natural_64_item)
else
create {JSON_NUMBER} Result.make_natural (0)
check
invalid_json_number: False
end
end
elseif attached {separate JSON_OBJECT} a_json_v as l_json then
create {JSON_OBJECT} Result.make_with_capacity (l_json.count)
check
attached {JSON_OBJECT} Result as l_res
then
across
l_json as l_item
loop
check
attached {JSON_VALUE} non_sep_json_value (l_item.item) as l_non_sep_json_value
then
create l_s.make_from_separate (l_item.key.item)
create l_json_s.make_from_string (l_s)
l_res.put (l_non_sep_json_value, l_json_s)
end
end
end
else
create {JSON_ARRAY} Result.make_empty
check
not_implemented: False
end
end
ensure
instance_free: Class
end