JSON produces incorrect empty array when compiled on Mac.

Feb 27, 2014 at 3:37 AM
Edited Feb 27, 2014 at 3:42 AM
The following code to create an empty JSON array produces an incorrect result when using libraries built for the Mac.

json::value v = json::value::array();
json::value jsonObject = json::value::object();
jsonObject[U("files")] = v;
string_t result = jsonObject.to_string();

result string on Windows
"files":[]

result string on Mac
"files":]
Feb 27, 2014 at 2:58 PM
I just tested on Windows (nugget package) and I am getting the same result you are getting on the Mac:

Image

This 'feels' somewhat similar to https://casablanca.codeplex.com/discussions/515102.

Yiannis
Feb 28, 2014 at 7:07 PM
Edited Feb 28, 2014 at 7:08 PM
This is a legit bug (json.h, v1.4.0):
            template<typename CharType>
            void format_impl(std::basic_string<CharType>& str) const
            {
                str.push_back('[');
                for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
                {
                    iter->second.format(str);
                    str.push_back(',');
                }
                str[str.size() - 1] = ']';
            }
The code tries to replace the last ',' character with the closing square bracket (']') but ends up replacing the opening bracket if there are no elements in the array.

Casablanca folks,
Can you please acknowledge?

Yiannis
Coordinator
Feb 28, 2014 at 7:16 PM
Hi Yiannis and John,

Yes this is a bug we know about, we actually have an issue already opened for it:

http://casablanca.codeplex.com/workitem/73

The fix is in our next release, for now you can use a work around mentioned in the issue, but will require you to re-build.

Steve
Feb 28, 2014 at 7:22 PM
Cool, thanks.

Yiannis