// JSON utilities for Lux // // This package provides convenient functions for working with JSON data. // It wraps the built-in JSON module with additional helpers. // Re-export built-in JSON functions pub fn parse(s: String): JsonValue = Json.parse(s) pub fn stringify(v: JsonValue): String = Json.stringify(v) // Get a string field from a JSON object pub fn getString(obj: JsonValue, key: String): Option = { Json.get(obj, key) } // Get an integer field from a JSON object pub fn getInt(obj: JsonValue, key: String): Option = { Json.get(obj, key) } // Get a nested field using dot notation pub fn getPath(obj: JsonValue, path: String): Option = { let keys = String.split(path, ".") List.fold(keys, Some(obj), fn(acc, key) => { match acc { Some(v) => Json.get(v, key), None => None } }) } // Check if a JSON value is null pub fn isNull(v: JsonValue): Bool = { match v { JsonNull => true, _ => false } } // Create a JSON object from key-value pairs pub fn object(pairs: List<(String, JsonValue)>): JsonValue = { Json.object(pairs) } // Create a JSON array from a list pub fn array(items: List): JsonValue = { Json.array(items) } // Pretty-print JSON with indentation pub fn prettyPrint(v: JsonValue): String = { prettyPrintIndent(v, 0) } fn prettyPrintIndent(v: JsonValue, indent: Int): String = { let spaces = String.repeat(" ", indent) // Simplified implementation Json.stringify(v) }