[v5.3.2] Loving the JSON manipulation, longing for array operators

Just quickly wanted to say that I absolutely LOVE that we now have a good set of filter operators for JSON data handling. I use tiddlywiki mainly for managing ttrpg campaigns, and have always dreamed of being able to use JSON for more fine-grained data handling.

However, I will continue to longingly wait for some sort of array manipulation filter operators, as these are not yet present (see issue #7840).

(I definitely will start using JSON for real in my ttrpg tiddlywikis now, and will for the time being use a “poor mans’s substitute” for JSON arrays, as my use of arrays would be limited to storing a series of alphanumerical strings in them. My intent, therefore, is to cobble together some tool manipulating TW “title lists”; these can then be transferred to and from JSON strings with the jsonset and jsonget filter operators…)

Agreed, Just keep in mind as the issue says;

Describe alternatives you’ve considered
Technically all of these can be done already using jsonget and jsonset , but the filter operations to achieve that result would be quite tedious to write, and rather inefficient to boot.

  • jsonset From Prerelease 5.3.2

Reading an array (a series of strings in my case) and manipulating it as a TW title list (including adding/deleting items) is not a problem. My problem is rather that I do not really know how to turn the title list back into a JSON array format in a proper fashion, for saving it back into place.

I will throw some testing at the proverbial wall tomorrow, to see if something sticks. If some kind soul could point me in the right general direction, I’d be much obliged.

I have a little trick I discovered that may interest you;

Now procedures, custom widgets, even templates and plain wikitext can use the parameters widget. The key attribute $params=vaname generates a small JSON array of parameter value pairs. You will find the use of $names and $values parameters on a few widgets like set multiple variables widget showing how to decompose the name values and it is not a big step to see how to reverse this.

These functions are useful

\function all.names(json) [<json>jsonindexes[]]
\function all.values(json) [<json>jsonindexes[]] :map[<json>jsonget<currentTiddler>]

See the Genesis widget


I can share more code examples if you are interested.