JSON Filtering Question


Hello all

I'm sure someone will be able to answer this...it's been driving me mad all weekend!

I've taken a CSV file and brought it into a JSON file object for use 'locally' within a future Dashboard UI operation, I am however struggling to only forward on specific properties and values of the message.

The CSV contains multiple rows. This is stored in a JSON file. It's then outputted and split by row into individual messages.

I then want to only forward specific columns / fields / objects (apologies if I haven't got the terminology correct) onwards in the flow.

I've been attempting to use various JSON filter nodes. It seems straight forward, enter the field names separated by commas and only these will be forward in the payload.


Instead of this occurring, I receive a message regarding:

The following field in the JSON filter configuration does not have a match in the data headers.

My efforts are below, can anyone help perform, what I'm sure, is a simple process that is doing my head in! :slight_smile:

Update: I note that taking a look at one of the msgs out of the JSON converter shows, what I think is an incomplete formatted JSON string. Invalid character? Length? I see ... at the end of the string. Is this what is upsetting the JSON filter...I bet it is. Any reasons why? Each message seems to have a slightly different length but are all ending, not with a curly bracket but ...

{"recordkey":"0","recordtimestamp":"2018-07-30 00:00:00.000","arrivalsite":"526524024","siterollup":"1","busunitkey":"1","calltypekey":"19","numreceived":"105","numreceivedreq":"0","numreceivednetin":"0","numansweredprim":"94","numansweredover":"0","numabandoned":"11","numredirectedoutscope":"0","numredirectednetout":"0","ansunderthreshold":"76","abnunderthreshold":"7","totanswaittime":"4734","totabanwaittime":"1192","totredirwaittime":"0","totwaittime":"5867","answered1":"34","answered2":"16","answered3":"6","answered4":"5","answered5":"33","abandoned1":"2","abandoned2":"1","abandoned3":"2","abandoned4":"0","abandoned5":"6","waitcountbegin":"0","waitcountend":"0","maxanswaittime":"349","maxabanwaittime":"366","maxredirwaittime":"0","maxcountwaiting":"3","mincountwaiting":"0","maxcountoverflows":"0","mincountoverflows":"0","numoverflows":"0","usersinvolvedtime":"10882","additionalhandledcount":"0","totcontacttime":"18238","additionalcontactcount":"0","totdefertime":"0","defercount":"0"...

Many, Many thanks.






The JSON node you are using is set to convert FROM a JSON string TO a javascript object.

You then feed it through a node designed to take in JSON and export TO a filtered Javascript Object.

If you can post your original CSV someone can probably suggest a more appropriate way of achieving your aim.



My favorite way to restructure JS objects is to use a change node and a JSONata expression -- to retrieve just the 3 properties you want, this expression should work:

    "recordtimestamp": recordtimestamp,
    "numreceived": $number(numreceived),
    "expiry": expiry

The JSONata expression language is a bit complex, but very powerful -- it is well worth the couple hours it takes to read through the whole jsonata.org site. There is even an expression "tester" built into the change node. When you pick the J: "expression" option and click the ... button on the right, you'll see this page:

From the debug sidebar, you can use the "copy value" button to grab any object as a JSON string, paste that into the left pane of the tester following "payload": in place of the "hello world" string -- then as you type your expression in the top editor, you will see the output in the right pane in real time... very nice.



How come I never noticed this before - brilliant tool :slight_smile: