martinzink commented on code in PR #1552:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1552#discussion_r1165654617


##########
extensions/windows-event-log/wel/JSONUtils.cpp:
##########
@@ -135,28 +157,37 @@ rapidjson::Document toJSONImpl(const pugi::xml_node& 
root, bool flatten) {
 
   {
     auto eventData_xml = event_xml.child("EventData");
-    // create EventData subarray even if flatten requested
-    doc.AddMember("EventData", rapidjson::kArrayType, doc.GetAllocator());
-    for (const auto& data : eventData_xml.children()) {
-      auto name_attr = data.attribute("Name");
-      rapidjson::Value item(rapidjson::kObjectType);
-      item.AddMember("Name", rapidjson::StringRef(name_attr.value()), 
doc.GetAllocator());
-      item.AddMember("Content", rapidjson::StringRef(data.text().get()), 
doc.GetAllocator());
-      item.AddMember("Type", rapidjson::StringRef(data.name()), 
doc.GetAllocator());
-      // we need to query EventData because a reference to it wouldn't be 
stable, as we
-      // possibly add members to its parent which could result in reallocation
-      doc["EventData"].PushBack(item, doc.GetAllocator());
-      // check collision
-      if (flatten && !name_attr.empty() && !doc.HasMember(name_attr.value())) {
-        doc.AddMember(rapidjson::StringRef(name_attr.value()), 
rapidjson::StringRef(data.text().get()), doc.GetAllocator());
+    if (flatten) {
+      for (const auto& event_data_child : eventData_xml.children()) {
+        std::string key = "EventData";
+        if (auto name_attr = event_data_child.attribute("Name").value(); 
strlen(name_attr)) {
+          key = utils::StringUtils::join_pack(key, ".", name_attr);
+        }
+
+        if (auto type = event_data_child.name(); strlen(type) > 0) {
+          key = utils::StringUtils::join_pack(key, ".", type);
+        }
+
+        doc.AddMember(rapidjson::Value(createUniqueKey(key, doc), 
doc.GetAllocator()).Move(), 
rapidjson::StringRef(event_data_child.text().get()), doc.GetAllocator());
+      }
+    } else {
+      auto& event_data = doc.AddMember("EventData", rapidjson::kArrayType, 
doc.GetAllocator());
+      for (const auto& event_data_child : eventData_xml.children()) {
+        auto name_attr = event_data_child.attribute("Name");
+        rapidjson::Value item(rapidjson::kObjectType);
+        item.AddMember("Name", rapidjson::StringRef(name_attr.value()), 
doc.GetAllocator());
+        item.AddMember("Content", 
rapidjson::StringRef(event_data_child.text().get()), doc.GetAllocator());
+        item.AddMember("Type", rapidjson::StringRef(event_data_child.name()), 
doc.GetAllocator());
+        doc["EventData"].PushBack(item, doc.GetAllocator());

Review Comment:
   This would lose the type information (which might be useful), we could do of 
course something similar to the flat output so something like this?
   ```
   "EventData": {
       "Foobar.Text": "Lorem ipsum"
   }
   ```
   But since this is only a bugfix for the flat output type I wouldnt change 
the simple format in this PR maybe we could file a Jira ticket and explore the 
possibilities there?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to