2

I need to change a date from YEAR to a fixed YYYY-MM-DD only if the value of the year is not null.

At the moment I have this

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing?": "=concat(@(1,Passing),-01-01'"
    }
  }
]

Input:

{
  "Passing": "2022",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

And the Output I'll like is

{
  "Passing": "2022-01-01",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

This is currently working fine but when I have a null value in Passing i get this, that I want to avoid.

{
  "Passing": "null-01-01",
  "Comments": "NotMentioned",
  "Team": "2",
  "modified_date": "2023-01-27 13:41:39",
  "Profile": "DM",
  "JobRole": "Tester"
}

I need to keep the "Passing" equal to "null" if there is no year in it.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Sinuers
  • 53
  • 5

2 Answers2

2

The suffixing ? operator of Passing attribute checks out for the existence, not for nullability.

You rather can use isNull function within a modify transformation spec in order to check the condition such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing": ["=isNull", "=concat(@(1,&),'-01-01')"]// the value is overwritten provided the Passing has a non-null value
    }
  }
]

where @(1,&) replicates the current value of the attribute Passing

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
0

I don't know what your Passing value is if it's not null, But you can use the below spec if you want to achieve to your desired output.

Spec:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Passing": "=concat(@(1,Passing),'-01-01')"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "Passing": {
        "-*": {
          "@": "&2"
        },
        "*": {
          "@1": "&2"
        }
      }
    }
  }
]

If Passing is null, you get null.

If Passing is 2023, you get 2023-01-01

Mohammadreza Khedri
  • 2,523
  • 1
  • 11
  • 22