# JSON Filtering Question

**URL:** https://discourse.nodered.org/t/json-filtering-question/3180
**Category:** General
**Created:** [16 September 2018 07:45 UTC](https://discourse.nodered.org/t/json-filtering-question/3180 "2018-09-16T07:45:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![M0CRT](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/m0crt/32/3071_2.png) [@M0CRT](https://discourse.nodered.org/u/M0CRT)
#### Post date: [16 September 2018 07:45 UTC](https://discourse.nodered.org/t/json-filtering-question/3180/1 "2018-09-16T07:45:53Z")

</div>

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.

_node-red-contrib-jsonfilter_

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! 🙂

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.

Mo

Flow:

[{"id":"fa812d1.7a10cd","type":"inject","z":"bcdf6cac.32951","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":198.8984375,"y":1976.9571151733398,"wires":[["db6b7e74.d3301"]]},{"id":"db6b7e74.d3301","type":"DataOut","z":"bcdf6cac.32951","collection":"50099a5.5a1f164","name":"CallTypeDaily","topic":"CallTypeDaily","error":true,"x":465.8828125,"y":1986.25390625,"wires":[["9b669ffd.78f5c"]]},{"id":"9b669ffd.78f5c","type":"split","z":"bcdf6cac.32951","name":"","splt":"\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":747.8907623291016,"y":1985.8327541351318,"wires":[["c6aa3e96.6c84e","ef73a6f6.a01ec8"]]},{"id":"c6aa3e96.6c84e","type":"json","z":"bcdf6cac.32951","name":"","property":"payload","action":"","pretty":false,"x":882.8827972412109,"y":2058.21492767334,"wires":[["11908911.8dbff7"]]},{"id":"11908911.8dbff7","type":"JSONFilter","z":"bcdf6cac.32951","name":"Filter","fields":"recordtimestamp,numreceived","expiry":5,"x":1089.88671875,"y":2092.46484375,"wires":[[]]},{"id":"50099a5.5a1f164","type":"json-db-collection","z":"","name":"CallTypeDaily","collection":"CallTypeDaily","save":true}]

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [16 September 2018 08:56 UTC](https://discourse.nodered.org/t/json-filtering-question/3180/2 "2018-09-16T08:56:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [16 September 2018 19:39 UTC](https://discourse.nodered.org/t/json-filtering-question/3180/3 "2018-09-16T19:39:58Z")

</div>

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:

```auto
payload.{
    "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](http://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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/550fbbb65094ca05d096e8a7004932f81499023d.png)

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.

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [16 September 2018 20:36 UTC](https://discourse.nodered.org/t/json-filtering-question/3180/4 "2018-09-16T20:36:44Z")

</div>

> [@shrickus](#):
>
> 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:

How come I never noticed this before - brilliant tool 🙂
