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}") }