Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Before you can work with such a file format, you have to convert (transform) this structure into a JSON structure. The same is true in case you would like to convert a given JSON document into a CSV structure, for example to upload to some external system

...

Transfrom CSV → JSON

For this, PIPEFORCE provides the transformer command transform.csv.json which expects a CSV file which complies with the RFC4189 standard in the body or as input parameter of the command and converts it to a JSON document which can then be used for further processing.

...

Code Block
languagejson
{
  "columnsCount": 1,
  "rowsCount": 3,
  "rows": [
    ["row1"],
    ["row2"],
    ["row3"]
  ]
}

Transform JSON → CSV

For transformation from a given JSON document to a CSV document, a conversion from JSON to a text structure is required. In such cases, a template based approach can be used. Here is an example to convert a given JSON to CSV using the FreeMarker Transformer command:

Code Block
languageyaml
body: {
        "columnsCount": 3,
        "rowsCount": 2,
        "headers": ["firstName","lastName","age"],
        "rows": [
          {
            "firstName": "Max",
            "lastName": "Smith",
            "age": "38"
          },
          {
            "firstName": "Susann",
            "lastName": "Mayr Wan",
            "age": "44"
          }
        ]
      }
pipeline:
  - transform.ftl:
      template: |
        "${body.headers[0]}", "${body.headers[1]}", "${body.headers[2]}"
        <#list body.rows as person>
          "${person.firstName}",  "${person.lastName}", "${person.age}"
        </#list>