# Parameter in JSON path query

**URL:** <https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919>\
**Category:** Ignition\
**Created:** [November 25, 2022, 10:53am UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919 "2022-11-25T10:53:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henning.e.heine](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/henning.e.heine/32/70958_2.png) [@henning.e.heine](https://forum.inductiveautomation.com/u/henning.e.heine)\
**Post date:** [November 25, 2022, 10:53am UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919/1 "2022-11-25T10:53:00Z")

</div>

Hi there!  
I would like to use a json path query in a named query, but I can't figure out how to use the named query paramters in the path query.

My query looks like this:

```auto
SELECT jsonb_path_query(payload->'Parameters', '$.*[*] ? (@.index == $i)', '{"i":110}') -> 'value' as value FROM table

```

Ideally I want to replace the index 110 with a named query parameter. I can not set the parameter because the path query is a string. I tried replacing '{"i":110}' with CONCAT('{"ind":','110','}'), that does not work.

I can make it work with system.db.runPrepQuery in a script, but it would be nice to use a named query.

Would appreciate any ideas how to make this work.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 25, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919/2 "2022-11-25T14:53:11Z")

</div>

Use:

```auto
concat('{"i":', :someParam, '110}')

```

---

<div class="post-metadata">

**Author:** ![henning.e.heine](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/henning.e.heine/32/70958_2.png) [@henning.e.heine](https://forum.inductiveautomation.com/u/henning.e.heine)\
**Post date:** [November 25, 2022, 4:33pm UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919/3 "2022-11-25T16:33:34Z")

</div>

> [@pturmel](#):
>
> `concat('{"i":', :someParam, '110}')`

Thanks for the reply. I think my description was not the best. I try to replace the index number (e.g. 110) with a parameter. So I was expecting this to work:

```auto
select jsonb_path_query(payload->'Parameters', '$.*[*] ? (@.index == $i)',concat('{"i":',:someParam,'}') ) -> 'value' as value
FROM table

```

... it does not: I get this error:

```auto
GatewayException: org.postgresql.util.PSQLException: ERROR: function jsonb_path_query(jsonb, unknown, text) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 9
	caused by Exception: org.postgresql.util.PSQLException: ERROR: function jsonb_path_query(jsonb, unknown, text) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 9

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 25, 2022, 5:06pm UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919/4 "2022-11-25T17:06:40Z")

</div>

That means the parameter is in fact being passed, but the DB doesn't think a string is appropriate for that function. I'm not familiar enough with that function to advise further.

---

<div class="post-metadata">

**Author:** ![henning.e.heine](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/henning.e.heine/32/70958_2.png) [@henning.e.heine](https://forum.inductiveautomation.com/u/henning.e.heine)\
**Post date:** [November 25, 2022, 5:35pm UTC](https://forum.inductiveautomation.com/t/parameter-in-json-path-query/66919/5 "2022-11-25T17:35:03Z")

</div>

Thanks @pturmel. after reading your comment it clicked.

This works:

```auto
select jsonb_path_query(payload->'Parameters','$.*[*] ? (@.index == $ind)', concat('{"ind":',:someParam,'}')::jsonb ) -> 'value' as value
FROM table

```

The function expects an jsonb object insted of a string.
