1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Humphrey JSON is a library facilitating the serialization and deserialization of JSON data. It is designed for web applications, but can be used in other contexts, and is well-integrated with the Humphrey web server.
//!
//! Learn more about Humphrey JSON [here](https://humphrey.whenderson.dev/json/index.html).
extern crate self as humphrey_json;
/// Brings useful traits and macros into scope.
///
/// ```
/// use humphrey_json::prelude::*;
/// ```
pub use *;
pub use Value;
/// Deserialize a JSON string into a Rust data structure.
///
/// ## Usage
/// ```
/// use humphrey_json::prelude::*;
///
/// #[derive(FromJson, IntoJson, Debug)]
/// struct User {
/// name: String,
/// country: String,
/// }
///
/// fn main() {
/// let json_string = r#"
/// {
/// "name": "William Henderson",
/// "country": "United Kingdom"
/// }"#;
///
/// let user: User = humphrey_json::from_str(json_string).unwrap();
///
/// println!("{:?}", user);
/// }
/// ```
///
/// ## Errors
/// This function returns a `ParseError` if the JSON string is invalid,
/// or if the JSON string is missing a required field.
/// Serialize a Rust data structure into a JSON string.
///
/// ## Usage
/// ```
/// use humphrey_json::prelude::*;
///
/// #[derive(FromJson, IntoJson)]
/// struct User {
/// name: String,
/// country: String,
/// }
///
/// fn main() {
/// let user = User {
/// name: "William Henderson".into(),
/// country: "United Kingdom".into(),
/// };
///
/// let json_string = humphrey_json::to_string(&user);
///
/// println!("{}", json_string);
/// }
/// ```
/// Serialize a Rust data structure into a JSON string, pretty-printed with indentation.
///
/// For more control over indentation, use [`Value::serialize_pretty`].
///
/// ## Usage
/// ```
/// use humphrey_json::prelude::*;
///
/// #[derive(FromJson, IntoJson)]
/// struct User {
/// name: String,
/// country: String,
/// }
///
/// fn main() {
/// let user = User {
/// name: "William Henderson".into(),
/// country: "United Kingdom".into(),
/// };
///
/// let json_string = humphrey_json::to_string_pretty(&user);
///
/// println!("{}", json_string);
/// }
/// ```