2

I am trying to write a jolt specification to transform an input JSON. I have the following input:

[{
    "id": "11500887",
    "created": "2023-03-16T18:34:24.485+0200",
    "items": [{
        "field": "status",
        "fieldtype": "jira",
        "fieldId": "status",
        "from": "10000",
        "fromString": "In Definition",
        "to": "1",
        "toString": "Open"
    }]
}, {
    "id": "11500905",
    "created": "2023-03-16T18:35:05.552+0200",
    "items": [{
        "field": "status",
        "fieldtype": "jira",
        "fieldId": "status",
        "from": "1",
        "fromString": "Open",
        "to": "10001",
        "toString": "Committed"
    }]
}, {
    "id": "11500907",
    "created": "2023-03-16T18:35:11.634+0200",
    "items": [{
        "field": "status",
        "fieldtype": "jira",
        "fieldId": "status",
        "from": "10001",
        "fromString": "Committed",
        "to": "3",
        "toString": "In Progress"
    }]
}, {
    "id": "12223186",
    "created": "2023-05-03T00:55:00.323+0300",
    "items": [{
        "field": "resolution",
        "fieldtype": "jira",
        "fieldId": "resolution",
        "from": null,
        "fromString": null,
        "to": "10008",
        "toString": "Done"
    }, {
        "field": "status",
        "fieldtype": "jira",
        "fieldId": "status",
        "from": "3",
        "fromString": "In Progress",
        "to": "10018",
        "toString": "In Testing"
    }]
}]

The expected output after the jolt transform is:

[{
    "date": "2023-03-16T18:34:24.485+0200",
    "field": "status",
    "from": "In Definition",
    "to": "Open"
}, {
    "date": "2023-03-16T18:35:05.552+0200",
    "field": "status",
    "from": "Open",
    "to": "Committed"
}, {
    "date": "2023-03-16T18:35:11.634+0200",
    "field": "status",
    "from": "Committed",
    "to": "In Progress"
}, {
    "date": "2023-05-03T00:55:00.323+0300",
    "field": "status",
    "from": "In Progress",
    "to": "Testing"
}]

Here is my current spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "items": {
          "*": {
            "@2,created": "[&3].date",
            "field": "[&3].field",
            "fromString": "[&3].from",
            "toString": "[&3].to"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "field": {
          "status": {
            "@2": "tmp.[]"
          }
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "tmp": []
    }
  },
  {
    "operation": "shift",
    "spec": {
      "tmp": [""]
    }
  }
]

I'm close, but I'm losing the last status change because it's embedded in an array and my spec is only working when there is one item in the array.

Any suggestions on how to fix it?

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

3 Answers3

1
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "created": "[#2].date",
        "items": {
          "*": {
            "field": {
              "status": {
                "@2,field": "[&5].field",
                "@2,fromString": "[&5].from",
                "@2,toString": "[&5].to"
              }
            }
          }
        }
      }
    }
  }
]

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 29 '23 at 09:40
0

You should just change your spec a little bit. Like the following JOLT spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "items": {
          "*": {
            "@2,created": "[&3][&1].date",
            "field": "[&3][&1].field",
            "fromString": "[&3][&1].from",
            "toString": "[&3][&1].to"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": ""
      }
    }
  }
]
Mohammadreza Khedri
  • 2,523
  • 1
  • 11
  • 22
0

Specification

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "created": "[&1].date",
        "items": {
          "*": {
            "field": "[&3].field",
            "fromString": "[&3].from",
            "toString": "[&3].to"
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "field": "@(1,field[1])",
        "to": "@(1,to[1])"
      }
    }
  }
]
Pushpraj Singh
  • 107
  • 1
  • 10
  • I write this specification according to our output. in our output "field" : "resolution" does not contain, that's why i does not contain "field" : "resolution" in my specification. – Pushpraj Singh May 24 '23 at 07:50