libhaystack/haystack/encoding/json.rs
1// Copyright (C) 2020 - 2022, J2 Innovations
2
3//! Implement Haystack [JSON (Hayson) Encoding](https://project-haystack.org/doc/docHaystack/Json)
4//!
5//! The implementation is based on the excellent [serde_json](https://docs.serde.rs/serde_json/) de/serialization framework.
6//!
7//! # Examples
8//!
9//! Encoding
10//! ```
11//! use libhaystack::val::*;
12//! let json = serde_json::to_string(&Value::make_true());
13//!
14//! assert_eq!(json.unwrap(), "true");
15//!
16//! let json = serde_json::to_string(&Value::make_coord_from(29.9792, 31.1342));
17//!
18//! assert_eq!(json.unwrap(), r#"{"_kind":"coord","lat":29.9792,"lng":31.1342}"#);
19//!
20//! ```
21//!
22//! Decoding
23//! ```
24//! use libhaystack::val::*;
25//! let list: Vec<Value> = serde_json::from_str(r#"[100, "foo", {"_kind": "marker"}]"#).expect("Valid JSON");
26//!
27//! assert_eq!(list.len(), 3);
28//!
29//! assert_eq!(list, vec![Value::make_number(100.0), Value::make_str("foo"), Value::make_marker()]);
30//!
31//! ```
32
33/// Hayson decoder
34#[cfg(feature = "json-decoding")]
35pub mod decode;
36#[cfg(feature = "json-encoding")]
37/// Hayson encoder
38pub mod encode;