1 // Copyright (c) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 //     http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 //! cargo build --example ylong_json_example
15 //! Simple use examples of serialization and deserialization of JsonValue.
16 
17 use std::io::stdout;
18 use ylong_json::JsonValue;
19 
20 const JSON_TEXT: &str = r#"
21 {
22     "null": null,
23     "true": true,
24     "false": false,
25     "number": 3.14,
26     "string": "Hello World!",
27     "array": [1, 2, 3],
28     "object": {
29         "key1": 1,
30         "key2": 2,
31         "key3": 3
32     }
33 }
34 "#;
35 
main()36 fn main() {
37     let value = JsonValue::from_text(JSON_TEXT).unwrap();
38     let mut console = stdout();
39     value.formatted_encode(&mut console).unwrap();
40     value.compact_encode(&mut console).unwrap();
41 }
42