MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / value_to_json

Method value_to_json

gql-cli/src/cli/output.rs:197–242  ·  view source on GitHub ↗

Convert a Value to a JSON value

(value: &Value)

Source from the content-addressed store, hash-verified

195
196 /// Convert a Value to a JSON value
197 fn value_to_json(value: &Value) -> serde_json::Value {
198 match value {
199 Value::String(s) => serde_json::Value::String(s.clone()),
200 Value::Number(n) => serde_json::json!(n),
201 Value::Boolean(b) => serde_json::Value::Bool(*b),
202 Value::Null => serde_json::Value::Null,
203 Value::DateTime(dt) => serde_json::Value::String(dt.to_string()),
204 Value::DateTimeWithFixedOffset(dt) => serde_json::Value::String(dt.to_string()),
205 Value::DateTimeWithNamedTz(tz, dt) => serde_json::json!({
206 "datetime": dt.to_string(),
207 "timezone": tz,
208 }),
209 Value::TimeWindow(tw) => serde_json::json!({
210 "start": tw.start.to_string(),
211 "end": tw.end.to_string(),
212 }),
213 Value::Path(path) => serde_json::json!(format!("{:?}", path)),
214 Value::Array(arr) | Value::List(arr) => {
215 serde_json::Value::Array(arr.iter().map(Self::value_to_json).collect())
216 }
217 Value::Vector(vec) => {
218 serde_json::Value::Array(vec.iter().map(|v| serde_json::json!(v)).collect())
219 }
220 Value::Node(node) => {
221 serde_json::json!({
222 "type": "node",
223 "id": node.id,
224 "labels": node.labels,
225 "properties": node.properties,
226 })
227 }
228 Value::Edge(edge) => {
229 serde_json::json!({
230 "type": "edge",
231 "id": edge.id,
232 "label": edge.label,
233 "from": edge.from_node,
234 "to": edge.to_node,
235 "properties": edge.properties,
236 })
237 }
238 Value::Temporal(temporal) => {
239 serde_json::json!(format!("{:?}", temporal))
240 }
241 }
242 }
243
244 /// Convert a Value to a CSV-safe string
245 fn value_to_csv_string(value: &Value) -> String {

Callers

nothing calls this directly

Calls 2

cloneMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected