Function object

Source
pub fn object<F>(fmt: F) -> impl DisplayJson + Display
where F: Fn(&mut JsonObjectFormatter<'_, '_, '_>) -> Result,
Expand description

A convenience function for creating JSON objects.

This is shorthand for json(|f| f.object(|f| fmt(f))), providing a more direct way to construct JSON objects without the extra nesting.

ยงExamples

let obj = nojson::object(|f| {
    f.member("name", "Alice")?;
    f.member("age", 30)
});
assert_eq!(obj.to_string(), r#"{"name":"Alice","age":30}"#);