0

I need to extract values from primary_keys array and join them into one string. But I'm having troubles with values extraction.

Simplified input json:

{
  "primary_keys": [
    "ITEM",
    "LOC",
    "COMP_ID"
  ],
  "ITEM": "ID158",
  "LOC": 41,
  "COMP_ID": "BPF",
  "VALUE": 0.78
}

Expected output:

{
  "PK": "ID158|41|BPF",
  "ITEM": "ID158",
  "LOC": 41,
  "COMP_ID": "BPF",
  "VALUE": 0.78
}

Content of primary_keys array may differ from one flowfile to another. I appreciate any input. thanks!

1 Answer 1

1

You can use modify-overwrite-beta transformation along with join function after deriving an array(PK) composed of the respective values for the each members of primary_keys array through use of shift transformations such as

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "primary_keys": {
        "*": {
          "*": { "$": "PK.@(4,&)" }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "PK": {
        "*": {
          "$": "&2"
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "PK": "=join('|',@(1,&))"
    }
  }
]

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.