LitJSON outputs invalid JSON in an edge case. I sometimes read JSON from a file into a JsonData object and write it back without touching it. That breaks empty lists and objects in the output.
When reading an empty list or an empty object, the type of a JsonData object remains at JsonType.None. In contrast, for non-empty lists, for example, the parser would invoke IList.Add() at least once, which would make JsonData set the correct type via EnsureList().
I fixed it - possibly a little naively - by invoking IList.Clear() and IDictionary.Clear() for instantiated lists and objects, respectively, which is a no-op with the side effect of making the JsonData object set its type.
I have demo code to reproduce the issue. (And I had hoped that I could attach files to a pull request...)
Hey there,
LitJSON outputs invalid JSON in an edge case. I sometimes read JSON from a file into a JsonData object and write it back without touching it. That breaks empty lists and objects in the output.
When reading an empty list or an empty object, the type of a JsonData object remains at JsonType.None. In contrast, for non-empty lists, for example, the parser would invoke IList.Add() at least once, which would make JsonData set the correct type via EnsureList().
I fixed it - possibly a little naively - by invoking IList.Clear() and IDictionary.Clear() for instantiated lists and objects, respectively, which is a no-op with the side effect of making the JsonData object set its type.
I have demo code to reproduce the issue. (And I had hoped that I could attach files to a pull request...)
Thomas