From fc64058c37d57632005187520ff29c43b77d93da Mon Sep 17 00:00:00 2001 From: Bob Roberts Date: Wed, 7 Jan 2026 11:32:28 -0800 Subject: [PATCH] Fix rt parser string output and trailing comma example and test --- examples/json5-trailing-comma-formatter/README.md | 8 ++++---- examples/json5-trailing-comma-formatter/src/main.rs | 8 ++++---- src/rt/parser.rs | 8 ++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/json5-trailing-comma-formatter/README.md b/examples/json5-trailing-comma-formatter/README.md index 82fe391..006b5f8 100644 --- a/examples/json5-trailing-comma-formatter/README.md +++ b/examples/json5-trailing-comma-formatter/README.md @@ -29,12 +29,12 @@ output // My Document { breakfast: [ - bacon, - eggs, - spam, // <-- a trailing comma will be added here + 'bacon', + 'eggs', + 'spam', // <-- a trailing comma will be added here ], objekt: { - nested: value, // <-- and here + nested: "value", // <-- and here }, // <--- and here } diff --git a/examples/json5-trailing-comma-formatter/src/main.rs b/examples/json5-trailing-comma-formatter/src/main.rs index fa3a05a..6d12a66 100644 --- a/examples/json5-trailing-comma-formatter/src/main.rs +++ b/examples/json5-trailing-comma-formatter/src/main.rs @@ -86,12 +86,12 @@ fn test() { let expected = String::from(r#"// My Document { breakfast: [ - bacon, - eggs, - spam, // <-- a trailing comma will be added here + 'bacon', + 'eggs', + 'spam', // <-- a trailing comma will be added here ], objekt: { - nested: value, // <-- and here + nested: "value", // <-- and here }, // <--- and here }"#); assert_eq!(res, expected) diff --git a/src/rt/parser.rs b/src/rt/parser.rs index 0a26c78..948a3b6 100644 --- a/src/rt/parser.rs +++ b/src/rt/parser.rs @@ -286,8 +286,12 @@ impl JSONValue { JSONValue::NaN => {String::from("Nan")} JSONValue::Hexadecimal(s) => {s.clone()} JSONValue::Bool(b) => b.to_string(), - JSONValue::DoubleQuotedString(s) => {s.clone()} - JSONValue::SingleQuotedString(s) => {s.clone()} + JSONValue::DoubleQuotedString(s) => { + format!("\"{s}\"") + } + JSONValue::SingleQuotedString(s) => { + format!("'{s}'") + } JSONValue::Unary { operator, value} => { format!("{operator}{value}") }