Support Questions
Find answers, ask questions, and share your expertise

How to use lookuprecord processor in NiFi if I have a nested json object like below?

Explorer

I have a JSON file myData.json having content below :

{
  "attributes": {
    "before": {
      "cw1234567": {
        "40": {
          "changed_by": "olivia"
        },
        "45": {
          "changed_by": "olivia"
        },
        "81": {
          "changed_by": "olivia"
        }
      }
    },
    "after": {
      "cw1234567": {
        "45": {
          "changed_by": "olivia"
        },
        "66": {
          "changed_by": "olivia"
        }
      }
    }
  },
  "action": "Changedev"
}

And I also have a my_lookup JSON which is stored in MongoDb. Something like below:

{
  "40": "olivia test",
  "45": "olivia test",
  "81": {
    "id": "81",
    "idPath": [
      "0",
      "64",
      "32",
      "81"
    ],
    "locked": 0,
    "name": "Test 5",
    "namePath": [
      "All Attributes",
      "New category 1",
      "New category 2",
      "New category 3"
    ],
    "parentId": 32
  }
}

Now, my use case is that I wanted to be able to append to the JSON file myData for each key that matches the my_lookup JSON.

Result something like below :

{
  "attributes": {
    "before": {
      "cw1234567": {
        "40": {
          "changed_by": "olivia"
        },
        "45": {
          "changed_by": "olivia"
        },
        "81": {
          "id": "81",
          "idPath": [
            "0",
            "64",
            "32",
            "81"
          ],
          "locked": 0,
          "name": "Test 5",
          "namePath": [
            "All Attributes",
            "new Category 1",
            "new category 2",
            "new category 3"
          ],
          "parentId": 32
        }
      }
    },
    "after": {
      "cw1234567": {
        "45": {
          "changed_by": "olivia"
        },
        "66": {
          "changed_by": "olivia"
        }
      }
    }
  },
  "action": "Changedev"
}

I have been trying to use LookupRecord processor for this but since I'm new to NiFi I'm a little confused how to use it correctly and what should I define as my key and schema text in this case. Any help will be appreciated.

0 REPLIES 0
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.