# Filter json database with conditions

**URL:** <https://discourse.nodered.org/t/filter-json-database-with-conditions/78975>\
**Category:** General\
**Tags:** function-node\
**Created:** [5 June 2023 21:05 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975 "2023-06-05T21:05:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [5 June 2023 21:05 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/1 "2023-06-05T21:05:28Z")

</div>

Hello,  
I have a variable json database like this format

```auto
{
    "success": true,
    "center": {
        "lot": 88,
        "lng": 99
    },
    "results": [
        {
            "id": 8524,
            "name": "Kkkk",
            "fuels": [
                {
                    "id": 514,
                    "num": 1.871,
                    "name": "Be",
                    "fID": 1,
                    "Self": false
                },
                {
                    "id": 589,
                    "num": 1.879,
                    "name": "Be",
                    "fID": 1,
                    "Self": true
                },
                {
                    "id": 687,
                    "num": 1.719,
                    "name": "G",
                    "fID": 2,
                    "Self": false
                },
             ],
            "location": {
                "lot": 1587,
                "lng": 1474
            },
            "insertDate": "2023",
            "address": "test",
            "tk": "hello"
        },
        {
            "id": 24864,
            "name": "aaaaaaaaaaaaa",
            "fuels": [
                {
                    "id": 51455,
                    "num": 1.879,
                    "name": "Be",
                    "fID": 1,
                    "Self": true
                },
                {
                    "id": 9841,
                    "num": 1.719,
                    "name": "Ga",
                    "fID": 2,
                    "Self": true
                },
            ],
            "location": {
                "lot": 47
                "lng": 45
            },
            "insertDate": "2023",
            "address": "hgjnn",
            "tk": "test"
        }
    ]
}

```

and I would like to filter the content of the data record where contains for example the "name: "Be" ("fID": 1).  
For example the filter resultat:

```auto
 ("name":) "Kkkk"
_______________
("num":) 1.871,
("name":) "Be",
("Self":) false
*******************
("num":) 1.879,
("name":) "Be",
("Self":) true
______________"insertDate": "2023"
====================

  "name": "aaaaaaaaaaaaa"
__________________
("num":) 1.879,
("name":) "Be",
("Self":) true
______________"insertDate": "2023"

```

I hope I was able to explain the task well.  
I trieded to resolve the problem with the switch-node or function node but unfortunately I havn't positive results...  
Some one can help me to resolve the problem?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 June 2023 22:23 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/2 "2023-06-05T22:23:46Z")

</div>

Input example has a couple of errors, for json format need to remove the extra commas.

Output is very vague. Do you want that exact string output or some form of object?

Maybe a better output example will help reduce the guessing.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [6 June 2023 18:22 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/3 "2023-06-06T18:22:49Z")

</div>

Hello @E1cid ,  
Thank you for your helpfulness.  
Sorry for the confision of the input json file. I forget to cancel some commas when I preparied a excpert of the input json file.  
Here the correct file (valid json):

```auto
{
	"success": true,
	"center": {
		"lot": 88,
		"lng": 99
	},
	"results": [{
			"id": 8524,
			"name": "Kkkk",
			"fuels": [{
					"id": 514,
					"num": 1.871,
					"name": "Be",
					"fID": 1,
					"Self": false
				},
				{
					"id": 589,
					"num": 1.879,
					"name": "Be",
					"fID": 1,
					"Self": true
				},
				{
					"id": 687,
					"num": 1.719,
					"name": "G",
					"fID": 2,
					"Self": false
				}
			],
			"location": {
				"lot": 1587,
				"lng": 1474
			},
			"insertDate": "2023",
			"address": "test",
			"tk": "hello"
		},
		{
			"id": 24864,
			"name": "aaaaaaaaaaaaa",
			"fuels": [{
					"id": 51455,
					"num": 1.879,
					"name": "Be",
					"fID": 1,
					"Self": true
				},
				{
					"id": 9841,
					"num": 1.719,
					"name": "Ga",
					"fID": 2,
					"Self": true
				}
			],
			"location": {
				"lot": 47,
				"lng": 45
			},
			"insertDate": "2023",
			"address": "hgjnn",
			"tk": "test"
		}
	]
}

```

Now I would like to filter the json file.  
I would like to filter all elements from the objects for example name: "kkkk" and name": "aaaaaaaaaaaaa" (the names are only examples and therfore are variable) that contains for example the name:"Be" (where is the name:Be the fID is 1). The structur from the json file is allways the same.  
For example the result/content of af a filter request what I would like:

Kkkk: (from source "name")  
+++++++++++  
1.871 (from source "num")  
Be (from source "name")  
false (from source "Self")  
°°°°°°°°°°°°°°°°°°  
1.879 (from source "num")  
Be (from source "name")  
true (from source "Self")  
+++++++++++  
2023 (from source "insertDate")

/////////////////////////////////////////////////////////////////////////////

aaaaaaaaaaaaa: (from source "name")  
+++++++++++  
1.879 (from source "num")  
Be (from source "name")  
true (from source "Self")  
+++++++++++  
2023 (from source "insertDate")

the conent in the braket are only information to explain more detailed the source of the filterinformation.

I hope I was able to explain the task well.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2023 18:43 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/4 "2023-06-06T18:43:28Z")

</div>

Try this It's fairly close , due to template limitations. Will let you work on it

```auto
[{"id":"d68df420c3c419a9","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"name","v":"Be","vt":"str"},{"p":"fID","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lot\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"num\":1.871,\"name\":\"Be\",\"fID\":1,\"Self\":false},{\"id\":589,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":687,\"num\":1.719,\"name\":\"G\",\"fID\":2,\"Self\":false}],\"location\":{\"lot\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":9841,\"num\":1.719,\"name\":\"Ga\",\"fID\":2,\"Self\":true}],\"location\":{\"lot\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":110,"y":3860,"wires":[["c62fd51268123011"]]},{"id":"c62fd51268123011","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($$.payload.results{\t $.name: {\t \"name\": $.name,\t \"fuels\": [$.fuels[$.fID = $$.fID and $.name = $$.name]],\t \"insertDate\":$.insertDate\t }\t}).*","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3860,"wires":[["c5ec8cb9fb1e5dee"]]},{"id":"c5ec8cb9fb1e5dee","type":"template","z":"b9860b4b9de8c8da","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{#payload}}\n{{name}}\n+++++++++++\n{{#fuels}}\n{{num}}\n{{name}}\n{{Self}}\n°°°°°°°°°°°°°°°°°°\n{{/fuels}}\n{{insertDate}}\n///////////////////////\n{{/payload}}\n","output":"str","x":480,"y":3860,"wires":[["0ceb4c62b14375c6"]]},{"id":"0ceb4c62b14375c6","type":"debug","z":"b9860b4b9de8c8da","name":"debug 199","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":3860,"wires":[]}]

```

Output

```auto
Kkkk
+++++++++++
1.871
Be
false
°°°°°°°°°°°°°°°°°°
1.879
Be
true
°°°°°°°°°°°°°°°°°°
2023
///////////////////////
aaaaaaaaaaaaa
+++++++++++
1.879
Be
true
°°°°°°°°°°°°°°°°°°
2023
///////////////////////

```

[edit] fix fID input.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [6 June 2023 19:26 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/5 "2023-06-06T19:26:17Z")

</div>

Hello @E1cid,  
Thank you verry much for your support and the code.  
I will try your nodes calmly in the next days and I give you a feedback.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [7 June 2023 19:18 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/6 "2023-06-07T19:18:58Z")

</div>

Hlle @E1cid ,  
Thank you for your code, too.  
It works with the example json file! 🕶  
Do you know where can I find good informationen for this topics like set msg.payload, format template,... to learn it and to delve your code?

Question:  
I get the json data with a request like this example: [[Set a request header : Node-RED](https://cookbook.nodered.org/http/set-request-header)]([https://Set](https://Set) a request header)  
Do you know how i have do modify your inject node that it works? :thinking

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [7 June 2023 19:28 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/7 "2023-06-07T19:28:22Z")

</div>

Jsonata documentaion is [here](http://docs.jsonata.org/overview)  
Mustache used in template is [here](http://mustache.github.io/mustache.5.html) ( the mustache i used in new example is two none empty lists nested, followed by an inverted selection)

Using a http request node i would have thought you just replace the inject node/s, and set it to output a parsed json. If that does not work show us a debug of http request nodes output.

p.s. This version may work better, added handling no result from search

```auto
[{"id":"d68df420c3c419a9","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"name","v":"Be","vt":"str"},{"p":"fID","v":"12","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lot\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"num\":1.871,\"name\":\"Be\",\"fID\":1,\"Self\":false},{\"id\":589,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":687,\"num\":1.719,\"name\":\"G\",\"fID\":2,\"Self\":false}],\"location\":{\"lot\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":9841,\"num\":1.719,\"name\":\"Ga\",\"fID\":2,\"Self\":true}],\"location\":{\"lot\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":110,"y":3860,"wires":[["c62fd51268123011"]]},{"id":"c62fd51268123011","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($$.payload.results{\t $.name: {\t \"name\": $.name,\t \"fuels\": [$.fuels[$.fID = $$.fID and $.name = $$.name]],\t \"insertDate\":$.insertDate\t }\t}).*[$exists($.fuels[0])]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":3860,"wires":[["c5ec8cb9fb1e5dee"]]},{"id":"ffe6a8fb97615df4","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"name","v":"Be","vt":"str"},{"p":"fID","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lot\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"num\":1.871,\"name\":\"Be\",\"fID\":1,\"Self\":false},{\"id\":589,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":687,\"num\":1.719,\"name\":\"G\",\"fID\":2,\"Self\":false}],\"location\":{\"lot\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"num\":1.879,\"name\":\"Be\",\"fID\":1,\"Self\":true},{\"id\":9841,\"num\":1.719,\"name\":\"Ga\",\"fID\":2,\"Self\":true}],\"location\":{\"lot\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":110,"y":3920,"wires":[["c62fd51268123011"]]},{"id":"c5ec8cb9fb1e5dee","type":"template","z":"b9860b4b9de8c8da","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{#payload}}\n{{name}}\n-------------\n{{#fuels}}\n{{num}}\n{{name}}\n{{Self}}\n-------------\n{{/fuels}}\n{{insertDate}}\n ______________ \n\n{{/payload}}\n{{^payload}}No Result for\nname: {{name}}\nfID: {{fID}}{{/payload}}","output":"str","x":480,"y":3860,"wires":[["0ceb4c62b14375c6"]]},{"id":"0ceb4c62b14375c6","type":"debug","z":"b9860b4b9de8c8da","name":"debug 199","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":3860,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [12 June 2023 18:00 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/8 "2023-06-12T18:00:00Z")

</div>

Hello @E1cid ,  
Sorry for the late response.  
Thank you for your nice version. It works and I like it! 🕶

I connected a debug node to the output of the post to HttpBin and I get a response.  
When I connect your nodeexample to my request header i get allways the message "No Result for name fueled.  
I connected the post to HttpBin (return a parsed JSON object) to your set.msg.payload. The inject nodes I cancelled.  
Question: Where I get the request for the msg.name = Be and msg.fuelId?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 June 2023 18:48 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/9 "2023-06-12T18:48:52Z")

</div>

> [@E1cid](#):
>
> If that does not work show us a debug of http request nodes output.

With out all the info all i can do is guess.  
You set msg.fID to the fID in the message before the change node, to the fID you are after, e.g. `1` make sure it is a number not a string. You set msg.name to the name you wish to search fo `"Be"`.

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [12 June 2023 19:10 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/10 "2023-06-12T19:10:12Z")

</div>

Hello @E1cid,  
sorry for the confusion.  
I show you my code. Maybe it is more understandable.

```auto
[{"id":"28957e037055f9ad","type":"function","z":"67e5e39e7b6a8e54","name":"set payload and headers","func":"msg.headers = {};\nmsg.headers = {\n};\n\n\nmsg.payload = {};\nmsg.payload = {\n 'region' : 9,\n 'province': 'RM',\n 'town' : 'Monterotondo',\n 'priceOrder':'desc', \n 'fuelType': '1-1',\n 'refuelingMode': 1\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":3640,"wires":[["032934fb12b24bb2"]]},{"id":"cf770b6810ef06f2","type":"inject","z":"67e5e39e7b6a8e54","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":140,"y":3640,"wires":[["28957e037055f9ad"]]},{"id":"032934fb12b24bb2","type":"http request","z":"67e5e39e7b6a8e54","name":"post to HttpBin","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://carburanti.mise.gov.it/ospzApi/search/area","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"credentials":{},"x":540,"y":3640,"wires":[["abee4808abae2642","c62fd51268123011"]]},{"id":"d68df420c3c419a9","type":"inject","z":"67e5e39e7b6a8e54","name":"","props":[{"p":"payload"},{"p":"name","v":"Be","vt":"str"},{"p":"fuelId","v":"12","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lat\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"price\":1.871,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":false},{\"id\":589,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":687,\"price\":1.719,\"name\":\"G\",\"fuelId\":2,\"isSelf\":false}],\"location\":{\"lat\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":9841,\"price\":1.719,\"name\":\"Ga\",\"fuelId\":2,\"isSelf\":true}],\"location\":{\"lat\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":170,"y":3760,"wires":[["c62fd51268123011"]]},{"id":"c62fd51268123011","type":"change","z":"67e5e39e7b6a8e54","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($$.payload.results{\t $.name: {\t \"name\": $.name,\t \"fuels\": [$.fuels[$.fuelId = $$.fuelId and $.name = $$.name]],\t \"insertDate\":$.insertDate\t }\t}).*[$exists($.fuels[0])]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":3760,"wires":[["c5ec8cb9fb1e5dee","525d43e58e968f9b"]]},{"id":"c5ec8cb9fb1e5dee","type":"template","z":"67e5e39e7b6a8e54","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{#payload}}\nName company: {{name}}\n-------------\n{{#fuels}}\nprice: {{price}}\nfuel: {{name}}\nisSelf: {{isSelf}}\n-------------\n{{/fuels}}\nDate and time: {{insertDate}}\n ______________ \n\n{{/payload}}\n{{^payload}}No Result for\nname: {{name}}\nfuelId: {{fuelId}}{{/payload}}","output":"str","x":560,"y":3760,"wires":[["0ceb4c62b14375c6"]]},{"id":"0ceb4c62b14375c6","type":"debug","z":"67e5e39e7b6a8e54","name":"debug 199","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":3760,"wires":[]},{"id":"abee4808abae2642","type":"debug","z":"67e5e39e7b6a8e54","name":"debug 201","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":3640,"wires":[]},{"id":"7df991ec4a32e86d","type":"inject","z":"67e5e39e7b6a8e54","name":"","props":[{"p":"payload"},{"p":"name","v":"Be","vt":"str"},{"p":"fuelId","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lat\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"price\":1.871,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":false},{\"id\":589,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":687,\"price\":1.719,\"name\":\"G\",\"fuelId\":2,\"isSelf\":false}],\"location\":{\"lat\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":9841,\"price\":1.719,\"name\":\"Ga\",\"fuelId\":2,\"isSelf\":true}],\"location\":{\"lat\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":170,"y":3840,"wires":[["c62fd51268123011","04979bd3d7004a7b"]]},{"id":"525d43e58e968f9b","type":"debug","z":"67e5e39e7b6a8e54","name":"debug 203","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":3840,"wires":[]},{"id":"04979bd3d7004a7b","type":"debug","z":"67e5e39e7b6a8e54","name":"debug 204","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":3840,"wires":[]}]

```

The example data in the inject nodes are a little different from the http request data.  
I used them only for different tests.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 June 2023 20:26 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/11 "2023-06-12T20:26:25Z")

</div>

You switched form fID in OG post to fuelId,. You should have notified use of this fact

I am still awaiting a debug of http request node, i have asked three times now. I try to help but when i ask for info you ignore my request, and offer something I did not ask for.

You still had cross over for changing the fID and typo's due to this.

As said in last post add the name and fuelId in a change node before the JSONata expression.

The http return does not contain any name's "Be".

This should work when name is "Be" and fuelId id 1, set in change node.

```auto
[{"id":"e6926a4555f50a3e","type":"inject","z":"b9860b4b9de8c8da","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"date","x":100,"y":4020,"wires":[["d00f26c8017f46e9"]]},{"id":"d00f26c8017f46e9","type":"function","z":"b9860b4b9de8c8da","name":"set payload and headers","func":"msg.headers = {};\nmsg.headers = {\n};\n\n\nmsg.payload = {};\nmsg.payload = {\n 'region' : 9,\n 'province': 'RM',\n 'town' : 'Monterotondo',\n 'priceOrder':'desc', \n 'fuelType': '1-1',\n 'refuelingMode': 1\n};\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":4020,"wires":[["1d8bb51c38acb99a"]]},{"id":"1d8bb51c38acb99a","type":"http request","z":"b9860b4b9de8c8da","name":"post to HttpBin","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://carburanti.mise.gov.it/ospzApi/search/area","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":500,"y":4020,"wires":[["0a4e9c551c73218d","89f87e77215f7336"]]},{"id":"0a4e9c551c73218d","type":"debug","z":"b9860b4b9de8c8da","name":"debug 201","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":4000,"wires":[]},{"id":"89f87e77215f7336","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"fuelId","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"name","pt":"msg","to":"Be","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"($$.payload.results{\t $.name: {\t \"name\": $.name,\t \"fuels\": [$.fuels[$.fuelId = $$.fuelId and $.name = $$.name]],\t \"insertDate\":$.insertDate\t }\t}).*[$exists($.fuels[0])]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":4140,"wires":[["be1bf5946d6e9650","c6137e1d72f2da72"]]},{"id":"8794ef747eeeb81b","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"success\":true,\"center\":{\"lat\":88,\"lng\":99},\"results\":[{\"id\":8524,\"name\":\"Kkkk\",\"fuels\":[{\"id\":514,\"price\":1.871,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":false},{\"id\":589,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":687,\"price\":1.719,\"name\":\"G\",\"fuelId\":2,\"isSelf\":false}],\"location\":{\"lat\":1587,\"lng\":1474},\"insertDate\":\"2023\",\"address\":\"test\",\"tk\":\"hello\"},{\"id\":24864,\"name\":\"aaaaaaaaaaaaa\",\"fuels\":[{\"id\":51455,\"price\":1.879,\"name\":\"Be\",\"fuelId\":1,\"isSelf\":true},{\"id\":9841,\"price\":1.719,\"name\":\"Ga\",\"fuelId\":2,\"isSelf\":true}],\"location\":{\"lat\":47,\"lng\":45},\"insertDate\":\"2023\",\"address\":\"hgjnn\",\"tk\":\"test\"}]}","payloadType":"json","x":130,"y":4140,"wires":[["89f87e77215f7336"]]},{"id":"be1bf5946d6e9650","type":"template","z":"b9860b4b9de8c8da","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{#payload}}\nName company: {{name}}\n-------------\n{{#fuels}}\nprice: {{price}}\nfuel: {{name}}\nisSelf: {{isSelf}}\n-------------\n{{/fuels}}\nDate and time: {{insertDate}}\n ______________ \n\n{{/payload}}\n{{^payload}}No Result for\nname: {{name}}\nfuelId: {{fuelId}}{{/payload}}","output":"str","x":520,"y":4140,"wires":[["89cad60e79bf2836"]]},{"id":"c6137e1d72f2da72","type":"debug","z":"b9860b4b9de8c8da","name":"debug 203","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":4220,"wires":[]},{"id":"89cad60e79bf2836","type":"debug","z":"b9860b4b9de8c8da","name":"debug 199","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":4140,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![EL\_tech](https://avatars.discourse-cdn.com/v4/letter/e/258eb7/32.png) [@EL\_tech](https://discourse.nodered.org/u/EL_tech)\
**Post date:** [12 June 2023 20:46 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/12 "2023-06-12T20:46:54Z")

</div>

Hi @E1cid ,  
sorry for the confusion.  
In the example of the json data I used for example the word "Be " instead the whole word.  
I'm a newbie with Nodered and so I have some understanding problems.  
So, now I will look your Programm and try to understand. Especially the change node how it works like a filter.  
Thank you for your helpfulness and your great patience! 💪

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 June 2023 20:47 UTC](https://discourse.nodered.org/t/filter-json-database-with-conditions/78975/13 "2023-06-26T20:47:41Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
