JSONUpdate Plugin

This is actually an action widget (<$action-jsonupdate/>) to allow the manipulation of JSON data tiddlers. I know there is the jsonset filter operator, which allows you to update JSON within a variable and then you can write that JSON back to a Tiddler if you like, but that was very limited for me.

I use the jsonindexes, jsonextract and jsonget extensively, to read data, but the jsonset functionality was severly lacking for my needs in writing updates back to my JSON tiddlers.

I have created an adventure style games system within TIddlywiki and all the data for rooms, items, and everything else to do with each individual game are stored in the text field of large JSON tiddlers, that way I do not have to have separate tiddlers for each room, object, person, etc, but rather all the data and external image links are stored in the JSON files, and using a single room tiddler, item tiddler and person tiddler, I am able to stay in a single Tiddler and simply swap out the variable values on a button click to appear to navigate to another room, but instead just updating the variables of the current Tiddler with the data pulled from and written to JSON tiddlers. Basically, it is a moo, mud, muck system, but fully visual, with images, animations, ambient audio sounds and dialog, and I would not have been able to create the game system in its current state without a proper way to easily write to my JSON tiddlers directly, on the fly.

So, I created this plugin to write to json tiddlers as a necessity to complete my project, and figured it may be useful for anyone else that needs to write to JSON tiddlers more easily.

I do not have any GitHub to store the code or anything like that, and I did not write this for official release, but as I find it so useful for my needs, I figured if anyone else wanted to use it, why not. So this was not my initial intent, so if I am posting this incorrectly, I apologize, but I am just uploading the plugin as a JSON if anyone wants to import it and use it, or not. It includes a full readme on how to use it.

$__plugins_jbardi_jsonupdate_v1.0.19.json (123.3 KB)

Updating to v1.0.19

  • Updated the format when targeting an array in the $path attribute.
  • Fixed bugs associated with merging vs overwriting to ensure data integrity.
  • Forced “de-duplicaiton” on update/batch when $unique=“true” (the default) to ensure consistancy in expected results.

Updating to v1.0.18

  • Added $debug-path attribute to override $path for determining what will be displayed in the debug.

Updating to v1.0.17

  • Implemented schema validation with $schema and $schema-path attributes for data integrity.
  • Added array as an additional value type.

Updating to v1.0.16

  • Added full Mustache.js templating functionality with $template attribute, allowing dynamic JSON construction from variables and $value attribute.
  • Ensured pretty-printing for arrays/objects in template output.

Updating to v1.0.15

  • Enhanced deep merge logic for $type=“object” to handle complex object updates without unintended overwrites.
  • Improved array item handling for deep merge.

Updating to v1.0.14

  • Introduced comprehensive frontend and backend type verification for $value attribute and existing JSON data at $path, significantly improving data safety.

Updating to v1.0.13

  • Serious issues caused JSON data to be overwritten and I introduced other bugs which broke core features. Hopefully it is all fixed now.

Updating to v1.0.12

  • fixed a bug that broke the ability to update arrays in v1.0.11.

Updated to v1.0.11

  • fixed a serious bug that allowed the overwriting of an object instead of merging

Updated to v1.0.10

  • fixed targeted portion of changed JSON to display in debug

Updated to v1.0.9 to include suggestions by @pmario:

  • removed unnecessary dev console logs
  • expanded the debugging options to include:
    • $debug/$debug=“true” - Both Modal and Console Log
    • $debug=“modal” - Modal Only
    • $debug=“console” - Console Only
    • $debug=“no” - No debugging (equivalent to omitting $debug altogether)
    • $debug=<<myDebugState>> - you can set the debug option dynamically
5 Likes

Thx for sharing.

There is no need to apologize if you contribute something back to the project. No matter where.

We’ll find a nice place😎

1 Like

I am interested in this program. Is there a url?

I did test your example code a bit. It (mostly) seems to work as intended, but there are a lot of console.log() in your code. → That’s OK, but they can not be disabled.

I thought the $debug option could be used to decide where to output the debug info. So eg:

  • $debug … show modal and print to dev console
  • $debug="modal" … show the modal … as it is now
  • $debug="console" … output to dev console – no modal
  • $debug="no" … disable debugging … this one will allow us to make it dynamic <<state/value>>

Just some thoughts

1 Like

Yeah, there is a lot of console logging, again, that was due to this not originally being meant for public use, and I was just doing some debugging during dev, and never removed them. That could be cleaned up to only have console.warn for like invalid JSON, basically just anything that actually stops the data from successfully being written to the JSON and nothing else.

As for the $debug options, that actually sounds like a great idea, much more polished and useful. Again, for my personal purposes, I only needed the modal, but as I went and dumped it on here, it should be more robust in its implementation for wider use.

I do have a point of clarification on the $display=“no” option. I am not quite clear on making it dynamic and the <<state/value>> idea. Could you clarify that for me? I feel dumb like I should know what it is you are referring to LOL

UPDATE: Ok, never mind, I figured it out. I updated it with the expanded $debug options and removed the unnecessary console logs.

Not currently. This is a personal project, a kind nostalgic labor of love, and not finalized quite yet. It was originally designed around a whole lot of tiddlers, and it was getting out of hand. So the redesigning of the entire system to work with JSON files, and the requirement to have a custom widget to deal with that has obviously caused a lack of forward movement, and more lateral movement on rewriting what was already in place. Eventually it will be at a place that it can be stably used, but for the time being, it is a side project when I am not working. Like the plugin, it was not initially meant for public use, but rather just for me, but, also like the plugin, it will probably be made available. Focusing on completion, then I’ll address what to do with it at that point.

1 Like