Possible corrupted jsondb in OH3

I have been (painstakingly slowly) moving toward openHAB 3. I’ve been running parallel Docker containers with my existing 2.5.11 install and a new release version of openHAB 3.

Along the way, I’ve edited the jsondb a few times when I couldn’t achieve what I wanted from the UI: renaming items and removing links that seem to have gotten “stuck” (unable to remove from the UI and only intermittently showing up).

Just a note- I’ve learned from this experience and don’t plan on editing the database directly unless I have no choice, and if I do so, plan a robust backup strategy.

I’ve noticed that my problems are persisting- I have difficulty in deleting items, changing links, and editing items from the UI.

To fix the issues, I’ve continued to edit the jsondb and I thought I had removed all of the orphaned links and corrupted items from the respective files. However, the whole point of my migration is to stop relying on text files and
to have a more stable install and through my (probably self-inflicted) issues I’m failing at both.

My next step is to nuke my OH3 setup and
start from scratch. Before I do, is there anything left to try to save my install?

Also, as an aside- will there be a textual export for items available anytime soon? If so I could get by and use that to save some work.

There might be some small inconsistencies in the JSONDB that was introduced through the manual editing but those shouldn’t impact your ability to create and modify new stuff from the UI. It might be worth exploring how you are creating and modifying things in the UI to see if there is something about the steps you are taking might be revealing a bug in how this is all managed. If there were a problem with the JSONDB severe enough to impact all your Items, it would probably be that it’s no longer syntactically correct in which case you wouldn’t be able to see any of your Items.

So I can’t answer your first question without more information. All I can say is you shouldn’t be seeing these sorts of problems frequently.

I too have had some Links become orphaned even while working through the UI but I can’t remember the steps I took when that happened. I deleted those Links from the JSONDB manually but through the REST API docs, not my hand editing the .json files. About the only thing you can’t do through the REST API docs like these is renaming an Item (because even with text configs there really isn’t a rename, there is a delete and recreate).

I’ve also recently had to change the name of some Items (I had a misspelling in one Item that needed to match some other Items for an Associated Items DP rule) and because I didn’t discover the error until I had created the rule, widgets, links, and a bunch of Item metadata it was worth the risk to edit it in JSONDB instead of recreating the Item. But this is and should only be a last resort.

I documented my procedure at OH 3 Tips and Tricks

To delete Items I find it works the best to do so from the Link. Navigate to the Link either from the Thing or from the Item and then click remove link and answer yes to also remove the Item. From the Channels page of a Thing, you have the option to remove all the links and their Items as well if you need to do it for a whole Thing.

Anyway, for your second question, probably not. It’s not so easy to achieve because that one line in a .items file is actually stored in three separate places in JSONDB, Items, Metadata, and Links. And the REST API doesn’t support “give me all the metadata on an Item” type queries so there is no way to get all the metadata. And in OH 3, the Item Metadata is really really important. Most of the work going into configuring an Item (at least in my experience) is in the metadata.

1 Like

As always, thanks for your detailed and helpful response.

It sounds like I might be jumping the gun on a full reinstall. My planned next steps:

  • Make sure there’s so leftover cruft from my incorrect item names anywhere in the jsondb folder. I had focused on the items and links files but am wondering if I should cast a wider net.

  • There’s a strange artifact showing up at the end of my items jsondb file (shows up as long line of question marks in VSCode). Not sure why I didn’t try this earlier but I’ll try removing it.

  • Remove every reference to the remote openHAB binding (because I’m done using it for now, not because of anything wrong with the binding).

  • Try running my json files through an online syntax checker (probably won’t find anything but can’t hurt).

  • Try to keep track of how I’m creating items and links and seeing if there’s a common thread to my problems.

I’m at work or I would be doing this now.

That’s a red flag that there might be something weird going on. Do you see any other stray characters in these files? Is it only that one file? The file is 100% text so there shouldn’t be that sort of stuff hanging out at the end.

The best approach seems to be to go to the Thing. Delete all the links and Items from there. Then delete the Thing. Then uninstall the binding.

Hi, don‘t know if it helps but I had a similar issue as I added an (incorrect) regular expression in stateDescription via UI. Screwed my JSON DB and I fixed it manually. I remember I touched three different json-files … something like …metadata… and … item… and …link… (sorry can’t check the exact names).

1 Like

Well, I’m honestly pretty confused at this point… I sat down to work on my checklist this morning and the unrecognized characters were gone from the jsondb file.

I checked the rest and there was nothing out of place.

Before I posted earlier, I tried the “unlink all” option at the bottom of the remote openHAB thing page, and only some of the channels unlinked. This morning, I tried it again, and it worked. I then successfully removed the thing.

I’ve definitely poked and prodded while trying to figure out OH3 so it’s certainly possible I did something similar - I’ll watch out for this, thanks!

It’s hard to say if my issues are actually fixed or not, but at this point I’ll be optimistic and watch for issues.