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
// Copyright 2025 Tree xie.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use ;
/// Extracts multiple string values from JSON data by keys
///
/// This function provides a safe way to extract multiple string values from JSON with the following features:
/// - Handles invalid JSON gracefully
/// - Converts non-string values to strings
/// - Returns empty strings for missing keys
/// - Maintains order of results matching input keys
///
/// # Arguments
/// * `data` - Byte slice containing JSON data
/// * `keys` - Array of keys to look up in the JSON object
///
/// # Returns
/// * Vector of strings containing the values, with empty strings for:
/// - JSON is invalid
/// - Key doesn't exist
/// - Value cannot be converted to string
///
/// # Examples
/// ```
/// let json = r#"{"name": "John", "age": 30}"#.as_bytes();
/// let results = json_get_strings(json, &["name", "age", "missing"]);
/// assert_eq!(vec!["John", "30", ""], results);
/// ```
/// Extracts a string value from JSON data by key
///
/// This function provides a safe way to extract string values from JSON with the following features:
/// - Handles invalid JSON gracefully
/// - Converts non-string values to strings
/// - Treats "null" values as empty strings
/// - Returns empty string for missing keys
///
/// # Arguments
/// * `data` - Byte slice containing JSON data
/// * `key` - Key to look up in the JSON object
///
/// # Returns
/// * String containing the value or empty string if:
/// - JSON is invalid
/// - Key doesn't exist
/// - Value is null
/// - Value cannot be converted to string
///
/// # Examples
/// ```
/// let json = r#"{"name": "John", "age": 30, "null_value": null}"#.as_bytes();
/// assert_eq!("John", json_get(json, "name"));
/// assert_eq!("30", json_get(json, "age"));
/// assert_eq!("", json_get(json, "null_value"));
/// assert_eq!("", json_get(json, "non_existent"));
/// ```
/// Extracts a string value from a JSON map by key
///
/// This function provides a safe way to extract string values from a JSON map with the following features:
/// - Handles missing keys gracefully
/// - Converts non-string values to strings
/// - Returns empty string for missing keys
///
/// # Arguments
/// * `data` - JSON map to extract value from
/// * `key` - Key to look up in the JSON map
///
/// # Returns
/// * String containing the value or empty string if:
/// - Key doesn't exist
/// - Value cannot be converted to string