Added ability to skip plain JSON arrays. [#METR-22801]

This commit is contained in:
Vitaliy Lyudvichenko 2016-09-28 16:11:03 +03:00
parent 68dffa3970
commit 3c045e1545
2 changed files with 33 additions and 3 deletions

View File

@ -810,7 +810,7 @@ inline void skipWhitespaceIfAny(ReadBuffer & buf)
++buf.position();
}
/// Skip json value (except array and object).
/// Skips json value. If the value contains objects (i.e. {...} sequence), an exception will be thrown.
void skipJSONFieldPlain(ReadBuffer & buf, const String & name_of_filed = "");

View File

@ -595,11 +595,41 @@ void skipJSONFieldPlain(ReadBuffer & buf, const String & name_of_filed)
{
assertString("true", buf);
}
else if (*buf.position() == 'f')/// skip false
else if (*buf.position() == 'f') /// skip false
{
assertString("false", buf);
}
else if (*buf.position() == '{' || *buf.position() == '[') /// fail on nested objects
else if (*buf.position() == '[')
{
++buf.position();
skipWhitespaceIfAny(buf);
if (!buf.eof() && *buf.position() == ']') /// skip empty array
{
++buf.position();
return;
}
while (true)
{
skipJSONFieldPlain(buf, name_of_filed);
skipWhitespaceIfAny(buf);
if (!buf.eof() && *buf.position() == ',')
{
++buf.position();
skipWhitespaceIfAny(buf);
}
else if (!buf.eof() && *buf.position() == ']')
{
++buf.position();
break;
}
else
throw Exception("Unexpected symbol for key '" + name_of_filed + "'", ErrorCodes::INCORRECT_DATA);
}
}
else if (*buf.position() == '{') /// fail on objects
{
throw Exception("Unexpected nested field for key '" + name_of_filed + "'", ErrorCodes::INCORRECT_DATA);
}