Nifi : JSON to .csv file transformation

52 Views Asked by At

I have a following input in Nifi Jolt Specification processor, that i got from an API :

{
  "BAG": {
    "Ett": "WWWLOG",
    "refD": "DVJOB1415738",
    "TO": "JOB",
    "tst": ""
  },
  "TC": {
    "Command": "DVJOB1415738",
    "dateCmd": "20/11/2026 10:25:16",
    "codeTransporteur": "999",
    "RProjet": "62165SUN_XXXXX_XXXXXX"
  },
  "buyer": {
    "id": "929292",
    "CMDM": "867220 SAN ANDREAS",
    "Exp": "021",
    "refB": "CIN1887881",
    "lieuL": "867220"
  },
  "CntShip": {
    "TC": "2",
    "cleR": "WWW",
    "FN": "ITASM",
    "LN": "DATA1",
    "Phone": "07********",
    "mail": "[email protected]"
  },
  "LC": [
    {
      "N": 1,
      "CArt": "3561920920832",
      "CArtDAPO": "",
      "Q": 1
    },
    {
      "N": 2,
      "CArt": "3561920936604",
      "CArtDAPO": "",
      "Q": 1
    },
    {
      "N": 3,
      "CArt": "2619000120519",
      "CArtDAPO": "",
      "Q": 1
    }
  ]
}

and from this input I want to get such output as a flatfile:

11|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|WWW|OFFER|JOB||20251120102517|
12|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|DVJOB1415738|20231120092516|999||929292|867220|||867220 SAN ANDREAS|021|||CIN1887881|
15|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|2|WWW|ITASM|DATA1|07********||[email protected]|
8|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|1|3561920956992|||1|||1||||62165SUN_XXXXX_XXXXXX||||||
8|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|2|3561920936604|||1|||2||||62165SUN_XXXXX_XXXXXX||||||
8|SHIP2023112009251776006143|WWWLOG|DVJOB1415738|3|2619000120519|||1|||3||||62165SUN_XXXXX_XXXXXX||||||
  • i Don't know if i use only JoltTransformation is enough to get this output, or i need to use others processors.
  1. while the first number in each line represent the level of the attribute for each line in our json file: for exemple 11=Bag, 12="TC & buyer", 15=CntShip , 8=LC for each article.

  2. the "SHIP2025112010251776006143" represent the "MSG_N" is should be generated by me using this form "SHIP+yyyyMMddHHMMSS+8randomNumbers" and be the same in all line of the output.

  3. The seconde and the third and 4th field should be the same for all the line in the output.

  4. The fields that is not empty but it wasn't mentionned in the input json file should be added after, like the six field in the first line "OFFER" or the 17 Field in the second line is also has to be generated by us

  5. the empty field "|||" that we have in our output represent a field in our excel file for the mapping, so even if their empty they should be added to the output,because they exist in our mapping file and represent more attribute.

So Please, Can you explain me how I can produce such an output ?

0

There are 0 best solutions below