diff --git a/spec/stdlib/cson-spec.coffee b/spec/stdlib/cson-spec.coffee index bee9e2032..6ec3ec12a 100644 --- a/spec/stdlib/cson-spec.coffee +++ b/spec/stdlib/cson-spec.coffee @@ -73,6 +73,8 @@ describe "CSON", -> it "returns formatted CSON", -> expect(CSON.stringify(a: {b: 'c'})).toBe "'a':\n 'b': 'c'" + expect(CSON.stringify(a:{})).toBe "'a': {}" + expect(CSON.stringify(a:[])).toBe "'a': []" describe "when converting back to an object", -> it "produces the original object", -> diff --git a/src/stdlib/cson.coffee b/src/stdlib/cson.coffee index 5b8527d75..6d703d578 100644 --- a/src/stdlib/cson.coffee +++ b/src/stdlib/cson.coffee @@ -94,7 +94,10 @@ module.exports = else if _.isArray(value) cson += " #{@stringifyArray(value, indentLevel)}" else if _.isObject(value) - cson += "\n#{@stringifyObject(value, indentLevel + 2)}" + if _.isEmpty(value) + cson += ' {}' + else + cson += "\n#{@stringifyObject(value, indentLevel + 2)}" else throw new Error("Unrecognized value type for key: #{key} with value: #{value}") prefix = '\n'