pub fn json<E: TextOrNullableText + MaybeNullableValue<Json>, e>(
e: e,
) -> json<E, e>where
e: AsExpression<E>,
Available on crate feature
sqlite
only.Expand description
Verifies that its argument is a valid JSON string or JSONB blob and returns a minified version of that JSON string with all unnecessary whitespace removed.
ยงExample
let result = diesel::select(json::<Text, _>(r#"{"a": "b", "c": 1}"#))
.get_result::<Value>(connection)?;
assert_eq!(json!({"a":"b","c":1}), result);
let result = diesel::select(json::<Text, _>(r#"{ "this" : "is", "a": [ "test" ] }"#))
.get_result::<Value>(connection)?;
assert_eq!(json!({"a":["test"],"this":"is"}), result);
let result = diesel::select(json::<Nullable<Text>, _>(None::<&str>))
.get_result::<Option<Value>>(connection)?;
assert!(result.is_none());