diff --git a/src/Val.cc b/src/Val.cc index 2da784de9b..a6958b35b5 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -494,8 +494,8 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new case TYPE_PORT: { auto* pval = val->AsPortVal(); - j["port"] = pval->Port(); - j["proto"] = pval->Protocol(); + j.emplace("port", pval->Port()); + j.emplace("proto", pval->Protocol()); break; } @@ -577,7 +577,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new else key_string = key_json.dump(); - j[key_string] = BuildJSON(entry_value, only_loggable, re); + j.emplace(key_string, BuildJSON(entry_value, only_loggable, re)); } Unref(lv); @@ -614,7 +614,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new Val* value = key_field->Lookup("value", true); if ( value && ( ! only_loggable || key_field->Lookup("log")->AsBool() ) ) - j[key_string] = BuildJSON(value, only_loggable, re); + j.emplace(key_string, BuildJSON(value, only_loggable, re)); } delete fields; @@ -646,9 +646,8 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new case TYPE_OPAQUE: { - j = ZeekJson::object(); auto* oval = val->AsOpaqueVal(); - j["opaque_type"] = OpaqueMgr::mgr()->TypeID(oval); + j = { { "opaque_type", OpaqueMgr::mgr()->TypeID(oval) } }; break; } diff --git a/src/threading/formatters/JSON.cc b/src/threading/formatters/JSON.cc index 58b1ffd779..096e823a10 100644 --- a/src/threading/formatters/JSON.cc +++ b/src/threading/formatters/JSON.cc @@ -37,7 +37,7 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields, if ( new_entry.is_null() ) return false; - j[fields[i]->name] = new_entry; + j.emplace(fields[i]->name, new_entry); } } @@ -182,11 +182,7 @@ ZeekJson JSON::BuildJSON(Value* val, const string& name) const } if ( ! name.empty() && ! j.is_null() ) - { - ZeekJson j2 = ZeekJson::object(); - j2[name] = j; - return j2; - } + return { { name, j } }; return j; } diff --git a/testing/btest/Baseline/scripts.base.utils.json/output b/testing/btest/Baseline/scripts.base.utils.json/output index 2d2e56253f..3be9649902 100644 --- a/testing/btest/Baseline/scripts.base.utils.json/output +++ b/testing/btest/Baseline/scripts.base.utils.json/output @@ -38,3 +38,4 @@ true {"10.1.1.1":{"a":1},"10.2.2.2":{"b":2}} {"10.1.1.1":[1,2],"10.2.2.2":[3,5]} {"1":{"s":"test"}} +{"opaque_type":"TopkVal"} diff --git a/testing/btest/scripts/base/utils/json.test b/testing/btest/scripts/base/utils/json.test index 6e7854b744..bec4a665b6 100644 --- a/testing/btest/scripts/base/utils/json.test +++ b/testing/btest/scripts/base/utils/json.test @@ -122,4 +122,8 @@ event zeek_init() print to_json(ta3); print to_json(ta4); print to_json(ta5, T); + + # Opaque + local o1: opaque of topk = topk_init(5); + print to_json(o1); }