Home > Mobile >  How to perform condition statement in input data
How to perform condition statement in input data

Time:12-01

I have a use case, where i need to match the name key-value and according to match, it'll post a result.

Input

{
  "Dv type": null,
  "Environment": null,
  "ipa": null,
  "category": null,
  "name": "ALPHA009",
  "Dv type0": "NYC",
  "Environment0": "sev",
  "ipa0": "X.Y.1",
  "category0": "test",
  "name0": "APLHA009"
}
  • if name == name0 then

    expected output will be

   {
    "Dv type0": "NYC",
    "Environment0": "sev",
    "ipa0": "X.Y.1",
    "category0": "test",
    "name0": "APLHA009"
  }
  • else when name != name0 then

    expected output will look like

  {
    "Dv type": null,
    "Environment": null,
    "ipa": null,
    "category": null,
    "name": "ALPHA009"
  }

CodePudding user response:

You can use the following specs after separating the elements tagged with or without zeroes such as

[
  {
    "operation": "shift",
    "spec": { // multiplex the objects while separating the cases for "name" vs "name0"
      "*0": {
        "@": "@(2,name0).n.o0.&1",
        "@(0)": "o0.&1"
      },
      "*": {
        "@": "@(2,name).n.o1.&1",
        "@(0)": "o1.&1"
      }
    }
  },
  { // calculate whether the size is 2 or not
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "n": "=size(@(1,&))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "n": {
          "2": { // if names are equal, then the both of the objects will reside within the same common object and the size will be two
            "@(3,o0)": "[]"
          },
          "*": { // else case
            "@(3,o1)": ""
          }
        }
      }
    }
  },
  { // pick only one from the objects generated, since two "n"s are generated for inequality case
    "operation": "shift",
    "spec": {
      "0": {
        "@": ""
      }
    }
  }
]

CodePudding user response:

You can use this spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "*0": "&"
    }
  }
]
  • Related