Fix for JSON formatter

In the event that the first entry in a record is optional AND not present, the serializer will incorrectly add a leading comma. This leading common is invalid JSON and will, more often than not, cause parser failures downstream.
This commit is contained in:
Aaron Eppert 2015-10-26 17:55:01 -04:00
parent 81d141959f
commit 295dbc3055

View file

@ -35,8 +35,14 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
const u_char* bytes = desc->Bytes();
int len = desc->Len();
if ( i > 0 && len > 0 && bytes[len-1] != ',' && vals[i]->present )
desc->AddRaw(",");
if ( i > 0 && len > 0 && bytes[len-1] != ',' && vals[i]->present ) {
// Issue if the first value of a record is optional AND not present
// then an empty json field will be produced, which is invalid.
// - ANE - 10/26/2015
if (len > 1 && bytes[len-1] != '{') {
desc->AddRaw(",");
}
}
if ( ! Describe(desc, vals[i], fields[i]->name) )
return false;