# OH3: jsondb -- extracting item names and state

**URL:** <https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689>\
**Category:** Items & Sitemaps\
**Tags:** items, json, itemstate\
**Created:** [March 17, 2024, 11:29pm UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689 "2024-03-17T23:29:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_G](https://community.openhab.org/user_avatar/community.openhab.org/max_g/32/64598_2.png) [@Max\_G](https://community.openhab.org/u/Max_G)\
**Post date:** [March 17, 2024, 11:29pm UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689/1 "2024-03-17T23:29:09Z")

</div>

- openHABian 3.4.3 on rPi4 with 4GB

This is a generic question, hence, no further detail about the specific hardware/software config.

I am trying to:

1. extract all item names from the `org.openhab.core.items.Item.json` file.  
**Solved:** `jq -r 'keys[]' org.openhab.core.items.Item.json`
2. ideally get a list of item names and their state

What I am really interested in, is more specific: find all items with state = UNDEF.  
However, listing items names is generically useful for me; so is any state. I should be able to apply relevant filters.

I tried `jq`, but could not make it work, as the first property name is the item, not the property value.

Any hints appreciated.

---

<div class="post-metadata">

**Author:** ![Oliver2](https://community.openhab.org/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@Oliver2](https://community.openhab.org/u/Oliver2)\
**Post date:** [March 17, 2024, 11:36pm UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689/2 "2024-03-17T23:36:09Z")

</div>

You can get all items from OH‘s rest API

```auto
http://openhab:8080/rest/items

```

and depending on what you want to achieve, parse the resulting json string.

---

<div class="post-metadata">

**Author:** ![Max\_G](https://community.openhab.org/user_avatar/community.openhab.org/max_g/32/64598_2.png) [@Max\_G](https://community.openhab.org/u/Max_G)\
**Post date:** [March 18, 2024, 12:05am UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689/3 "2024-03-18T00:05:04Z")

</div>

Thanks… this and `jq` will work (for my json file).

Solution:

1. Open: `http://openhabian:8080/rest/items`
2. Save this file as `rest_items.json`
3. Run `jq 'map(select(.state | contains("UNDEF")))' rest_items.json | grep -i link`
4. Which will produce this:

```auto
    "link": "http://openhabian:8080/rest/items/Driver40Troffer03_ColourTemperature",
    "link": "http://openhabian:8080/rest/items/fbox_outgoing_call",
    "link": "http://openhabian:8080/rest/items/fbox_incoming_call",
    "link": "http://openhabian:8080/rest/items/fbox_active_call",
    "link": "http://openhabian:8080/rest/items/Shed_KDL_ColourTemperature",
    "link": "http://openhabian:8080/rest/items/gTeslaM3_tire_pressure",
    "link": "http://openhabian:8080/rest/items/fbox_resolved_name",

```

Of course variations are possible; e.g., use curl to get the actual data passed into `jq`.

---

<div class="post-metadata">

**Author:** ![Oliver2](https://community.openhab.org/letter_avatar_proxy/v4/letter/o/df705f/32.png) [@Oliver2](https://community.openhab.org/u/Oliver2)\
**Post date:** [March 18, 2024, 6:49am UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689/4 "2024-03-18T06:49:50Z")

</div>

You can also limit the output to the desired fields:

```auto
http://oh:8080/rest/items?fields=link,state

```

would have been nice if we could add `&state=NULL` to the get request.

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [March 18, 2024, 1:47pm UTC](https://community.openhab.org/t/oh3-jsondb-extracting-item-names-and-state/154689/5 "2024-03-18T13:47:44Z")

</div>

> [@Max\_G](#):
>
> This is a generic question, hence, no further detail about the specific hardware/software config.

This often leads to XY Problems as questions like this exclude other possiblities which might be a better approach over all.

> [@Max\_G](#):
>
> I tried `jq`, but could not make it work, as the first property name is the item, not the property value.

As @Oliver2 indicates, you’ll only be able to get access to the Item’s states through the REST API. But once you have that you’ll be able to use `jq` to parse out what you need.

You could also do this in a quick rule if all you are after are the names of the UNDEF Items. In JS it would be:

```
items.filter( i => i.state == "UNDEF" ).forEach( i => console.log(i.name + " is UNDEF") );

```

In Rules DSL it would be something like:

```
org.eclipse.smarthome.model.script.ScriptServiceUtil.getItemRegistry().getItems().filter[i | i.state == UNDEF].forEach[i | logInfo('UNDEF Items', i.name + ' is UNDEF')]

```

Oh, and I forgot to mention that the Developer Sidebar can search Item states. So searching for NULL there will show all the Items that are NULL.

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/7/4/74edd68e272f0c612316b836146d801641c461ed.png)

However, I’m not sure the sidebar search does that in OH 3.
