Class JsonArrayToCSV

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent
    Direct Known Subclasses:
    JsonToFixedCSV

    @ComponentProfile(summary="Transfrom a JSON Array/JSON Lines document into a CSV",
                      tag="service,csv,json")
    public class JsonArrayToCSV
    extends CSVConverter
    Transfrom a JSON array into a CSV.

    Takes a JSON array and renders it as a CSV document:

     
     [
       { "firstname":"alice", "lastname":"smith", "dob":"2017-01-01" },
       { "firstname":"bob", "lastname":"smith", "dob":"2017-01-02" },
       { "firstname":"carol", "lastname":"smith", "dob":"2017-01-03" }
     ]
     
    will effectively render as
     
     firstname, lastname, dob
     "alice","smith", "2017-01-01"
     "bob", "smith", "2017-01-02"
     "carol","smith", "2017-01-03"
     
     

    nested JSON objects will be rendered as strings before being passed into the appropriate statement; so { "firstname":"alice", "lastname":"smith", "address": { "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}} still only be 3 CSV columns the address column will be "{ "address" : "Buckingham Palace", "postcode":"SW1A 1AA"}"

    In the adapter configuration file this class is aliased as json-to-csv which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • JsonArrayToCSV

        public JsonArrayToCSV()
    • Method Detail

      • withIncludeHeader

        public <T extends JsonArrayToCSV> T withIncludeHeader​(java.lang.String s)
      • getIncludeHeader

        public java.lang.String getIncludeHeader()
        Whether or not to emit a header line.
      • setIncludeHeader

        public void setIncludeHeader​(java.lang.String includeHeader)
        Whether or not to emit a header line.
      • getJsonStyle

        public JsonProvider.JsonStyle getJsonStyle()
        Specify how the payload is parsed to provide JSON objects.

        The default if not specified is a JSON_ARRAY

      • setJsonStyle

        public void setJsonStyle​(JsonProvider.JsonStyle jsonStyle)
        Specify how the payload is parsed to provide JSON objects.

        The default if not specified is a JSON_ARRAY