diff --git a/core/json/mod.rs b/core/json/mod.rs index 4d61fae0e..de97c8f78 100644 --- a/core/json/mod.rs +++ b/core/json/mod.rs @@ -863,6 +863,8 @@ mod tests { let integer_value = OwnedValue::Integer(1); let float_key = OwnedValue::build_text(Rc::new("float_key".to_string())); let float_value = OwnedValue::Float(1.1); + let null_key = OwnedValue::build_text(Rc::new("null_key".to_string())); + let null_value = OwnedValue::Null; let input = vec![ text_key, @@ -873,6 +875,8 @@ mod tests { integer_value, float_key, float_value, + null_key, + null_value, ]; let result = json_object(&input).unwrap(); @@ -881,7 +885,7 @@ mod tests { }; assert_eq!( json_text.value.as_str(), - r#"{"text_key":"text_value","json_key":{"json":"value","number":1},"integer_key":1,"float_key":1.1}"# + r#"{"text_key":"text_value","json_key":{"json":"value","number":1},"integer_key":1,"float_key":1.1,"null_key":null}"# ); } diff --git a/testing/json.test b/testing/json.test index 758243bcd..ea1c9bf0f 100755 --- a/testing/json.test +++ b/testing/json.test @@ -506,3 +506,41 @@ do_execsql_test json_error_position_null { do_execsql_test json_error_position_complex { SELECT json_error_position('{a:null,{"h":[1,[1,2,3]],"j":"abc"}:true}'); } {{9}} + +do_execsql_test json_object_simple { + SELECT json_object('key', 'value'); +} {{{"key":"value"}}} + +do_execsql_test json_object_nested { + SELECT json_object('grandparent',json_object('parent', json_object('child', 'value'))); +} {{{"grandparent":{"parent":{"child":"value"}}}}} + +do_execsql_test json_object_quoted_json { + SELECT json_object('parent', '{"child":"value"}'); +} {{{"parent":"{\"child\":\"value\"}"}}} + +do_execsql_test json_object_unquoted_json { + SELECT json_object('parent', json('{"child":"value"}')); +} {{{"parent":{"child":"value"}}}} + +do_execsql_test json_object_multiple_values { + SELECT json_object('text', 'value', 'json', json_object('key', 'value'), 'int', 1, 'float', 1.5, 'null', null); +} {{{"text":"value","json":{"key":"value"},"int":1,"float":1.5,"null":null}}} + +do_execsql_test json_object_empty { + SELECT json_object(); +} {{{}}} + +do_execsql_test json_object_json_array { + SELECT json_object('ex',json('[52,3]')); +} {{{"ex":[52,3]}}} + +do_execsql_test json_from_json_object { + SELECT json(json_object('key','value')); +} {{{"key":"value"}}} + +# FIXME: this behaviour differs from sqlite. Although, sqlite docs states +# that this could change in a "future enhancement" (https://www.sqlite.org/json1.html#jobj) +#do_execsql_test json_object_duplicated_keys { +# SELECT json_object('key', 'value', 'key', 'value2'); +#} {{{"key":"value2"}}}