locked
Supress double quotes in output string. JSON to CSV Conversion RRS feed

  • Question

  • I have a simple UDF which converts incoming JSON events to CSV. The UDF looks something like

    function toCSV(obj) {    
       return Object.keys(obj).map(v => obj[v]).join(',') + '\r\n';
    }

    And the Stream Analytics query is

    SELECT udf.toCSV(input) INTO blob-storage-output FROM stream-input as input

    However for a JSON input which gets deserialized as from

    { seq: 1, col1: "val1", col2: "val2" }
    { seq: 2, col1: "val21", col2: "val22" }

    The output that gets produced in CSV format is

    There are two issues here

    toCSV
    "1,va1,val2"
    "2,val21,val22"

    The function name appears as a first row. I want to suppress this. I don't need any header in this instance.

    The other being the output is written out in Double quotes("1,va1,val2"). This is not a valid CSV output. Is there anyway I can suppress this for getting written out?

    The Serialization on blob-storage-output OUTPUT is of type CSV with comma delimited.


    Tuesday, May 22, 2018 8:44 PM

All replies

  • I thought Stream Analytics will let you read an input from JSON and write an output to CSV. Why do you need to do this function manually through UDF? is it just to play with UDF features?

    On the blob output, you can pick the format as CSV:

    Event serialization format Serialization format for output data. JSON, CSV, and Avro are supported.

    I don't think CSV output has any option to remove headers. Someone requested that wish here: 
    https://feedback.azure.com/forums/270577-stream-analytics/suggestions/7235484-allow-more-flexible-file-formats-for-blob-storage

    Sounds like a decent idea to me. Probably worth tracking a new request. Checkbox to "include headers" or not.


    IF you didn't get enough help here, request assisted support from the Azure Support team for a deeper investigation: https://portal.azure.com/#blade/Microsoft_Azure_Support/HelpAndSupportBlade/overview

    Tuesday, May 22, 2018 10:43 PM