forma_json 0.1.0

JSON serialization and deserialization for forma_core.
Documentation
  • Coverage
  • 27.94%
    19 out of 68 items documented1 out of 48 items with examples
  • Size
  • Source code size: 181.02 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.82 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • scalecode-solutions

forma_json

JSON serializer and deserializer for the forma serialization framework.

Most users should use forma with the json feature instead of depending on this crate directly:

[dependencies]
forma = { version = "0.1", features = ["derive", "json"] }

Quick Example

use forma_json::{to_string, to_string_pretty, from_str, Value};

// Serialize to JSON
let json = to_string(&value).unwrap();
let pretty = to_string_pretty(&value).unwrap();

// Deserialize from JSON
let v: MyStruct = from_str(&json).unwrap();

// Dynamic Value type
let val: Value = from_str(r#"{"key": [1, 2, 3]}"#).unwrap();
assert_eq!(val["key"][0].as_u64(), Some(1));

API

  • to_string / to_string_pretty -- serialize to a JSON string.
  • to_vec / to_writer -- serialize to bytes or an io::Write.
  • from_str / from_slice -- deserialize from a string or byte slice.
  • Value -- dynamic JSON type with Index support for convenient access.
  • to_value / from_value -- convert between typed values and Value.

Lenient Mode

The deserializer accepts standard JSON. Lenient extensions (trailing commas, comments) may be added in a future release behind a feature flag.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.