JSON produces incorrect empty array when compiled on Mac.

Feb 27, 2014 at 2:37 AM
Edited Feb 27, 2014 at 2: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

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


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

Feb 28, 2014 at 6:07 PM
Edited Feb 28, 2014 at 6:08 PM
This is a legit bug (json.h, v1.4.0):
            template<typename CharType>
            void format_impl(std::basic_string<CharType>& str) const
                for (auto iter = m_elements.begin(); iter != m_elements.end(); ++iter)
                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?

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

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


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.

Feb 28, 2014 at 6:22 PM
Cool, thanks.