mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add LogAscii::json_include_unset_fields flag to control unset field rendering
The flag controls whether JSON rendering includes unset &optional log fields (F, the default), or includes them with a null value (T).
This commit is contained in:
parent
7a6501296b
commit
1aaed1cc2e
9 changed files with 62 additions and 12 deletions
|
@ -28,7 +28,8 @@ bool JSON::NullDoubleWriter::Double(double d)
|
|||
return rapidjson::Writer<rapidjson::StringBuffer>::Double(d);
|
||||
}
|
||||
|
||||
JSON::JSON(MsgThread* t, TimeFormat tf) : Formatter(t), surrounding_braces(true)
|
||||
JSON::JSON(MsgThread* t, TimeFormat tf, bool arg_include_unset_fields)
|
||||
: Formatter(t), surrounding_braces(true), include_unset_fields(arg_include_unset_fields)
|
||||
{
|
||||
timestamps = tf;
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const* fields, Val
|
|||
|
||||
for ( int i = 0; i < num_fields; i++ )
|
||||
{
|
||||
if ( vals[i]->present )
|
||||
if ( vals[i]->present || include_unset_fields )
|
||||
BuildJSON(writer, vals[i], fields[i]->name);
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ bool JSON::Describe(ODesc* desc, Value* val, const std::string& name) const
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( ! val->present || name.empty() )
|
||||
if ( (! val->present && ! include_unset_fields) || name.empty() )
|
||||
return true;
|
||||
|
||||
rapidjson::Document doc;
|
||||
|
@ -86,15 +87,15 @@ Value* JSON::ParseValue(const std::string& s, const std::string& name, TypeTag t
|
|||
|
||||
void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& name) const
|
||||
{
|
||||
if ( ! name.empty() )
|
||||
writer.Key(name);
|
||||
|
||||
if ( ! val->present )
|
||||
{
|
||||
writer.Null();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! name.empty() )
|
||||
writer.Key(name);
|
||||
|
||||
switch ( val->type )
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue