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
/// Creates a `JsonValue` from a JSON-like syntax.
///
/// This macro allows you to create JSON objects, arrays, and values using a syntax
/// that closely resembles JSON. It supports nested structures and automatically
/// converts Rust types to their JSON equivalents.
///
/// # Examples
///
/// Creating a JSON object:
/// ```
/// use rusty_json::base::{JsonObject, JsonValue};
/// use rusty_json::json;
///
/// let person = json!({
/// name: "Alice",
/// age: 30,
/// is_student: false,
/// hobbies: ["reading", "cycling"],
/// address: null
/// });
///
/// assert_eq!(person["name"].parse::<String>().unwrap(), "Alice");
/// assert_eq!(person["age"].parse::<i64>().unwrap(), 30);
/// assert_eq!(person["is_student"].parse::<bool>().unwrap(), false);
/// assert_eq!(person["hobbies"][0].parse::<String>().unwrap(), "reading");
/// assert_eq!(person["address"], JsonValue::Null);
/// ```
///
/// Creating a JSON array:
/// ```
/// use rusty_json::base::{JsonArray, JsonValue};
/// use rusty_json::json;
///
/// let numbers = json!([1, 2, null, 4, 5]);
///
/// let arr = JsonArray::from(numbers);
///
/// assert_eq!(arr[0].parse::<i64>().unwrap(), 1);
/// assert_eq!(arr[2], JsonValue::Null);
/// assert_eq!(arr[4].parse::<i64>().unwrap(), 5);
/// ```
///
/// Creating a simple JSON value:
/// ```
/// use rusty_json::{is_null, json};
/// use rusty_json::base::JsonValue;
///
/// let string_value = json!("Hello, World!");
/// let number_value = json!(42);
/// let bool_value = json!(true);
/// let null_value = json!(null);
///
/// assert_eq!(string_value.parse::<String>().unwrap(), "Hello, World!");
/// assert_eq!(number_value.parse::<i64>().unwrap(), 42);
/// assert_eq!(bool_value.parse::<bool>().unwrap(), true);
/// assert!(is_null!(null_value));
/// ```
///
/// # Note
///
/// This macro uses `$crate` to refer to the current crate. Ensure that the
/// necessary types (`JsonObject`, `JsonArray`, `JsonValue`) are available
/// in your crate's base module or adjust the paths accordingly.
/// Checks if a `JsonValue` is `Null`.
///
/// This macro simplifies the process of checking if a given `JsonValue` is `Null`.
///
/// # Examples
///
/// ```
/// use rusty_json::base::JsonValue;
/// use rusty_json::is_null;
///
/// let null_value = JsonValue::Null;
/// let non_null_value = JsonValue::Number(42.into());
///
/// assert!(is_null!(null_value));
/// assert!(!is_null!(non_null_value));
/// ```
///
/// # Note
///
/// This macro matches a `JsonValue::Null` variant. Ensure that the
/// `JsonValue` type is available in your crate's base module or adjust the
/// paths accordingly.