Home > Mobile >  JOLT transformation filter a list about the first string element
JOLT transformation filter a list about the first string element

Time:01-13

I would like to search a list for the first real string element (which could be not a number) and output this.

Input:

"firstString": ["0.20", "test", "0.30"] or "firstString": ["0.20", "0,30", "test"]

Expected Output:

"readingS": "test"

The order of the element can change, either it comes to 2nd or 3rd placeholder. The list is maximum 3 elements long. My thought was to go over either the last or middle element, however this does not work. The list is generated just before with the modify-overwrite-beta.

CodePudding user response:

You have some values that ended with numbers. So we can match all values that ended with the number, and we have a real string in the last.

[
  {
    "operation": "shift",
    "spec": {
      "firstString": {
        "*": {
          "*0": "",
          "*1": "",
          "*2": "",
          "*3": "",
          "*4": "",
          "*5": "",
          "*6": "",
          "*7": "",
          "*8": "",
          "*9": "",
          "*": {
            "$": "readingS"
          }
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
  }
]

enter image description here

  •  Tags:  
  • Related