I’m letting my game numerical setup (game planning?) intern using tw to write game data JSON like the one similar to CDDA’s JSON
Or dwarf fortress’s token
I’m now asking my intern to write a components field for tiddler “XXX” as components: [[XXX's components]],
and then in another tiddler “XXX’s components” write fields like "2x4": 1, "nail": 5.
Fields like qualities will be similar. Write qualities: Hammer1 Cut2 (tiddler title separated by space means list in tiddlywiki) in tiddler “XXX”,
and in tiddler “Hammer1” write fields like "id": "HAMMER", "level": 1
Do you have better solutions? Possible solutions I think can be:
using json path string like the one in lodash.get: a[0].b.c: xxx to express { a: [{ b: { c: 'xxx' } } ] }
write JSON in the text field, and set type to application/json, but my intern doesn’t know what “JSON” means. And I also want the input process to be simple.
Point them to https://JSON.org to see the spec and tell them, that all browsers can deal with JSON out of the box now. So no 3rd party stuff needed for parsing and creating.
With the new json-related filter operators it is easier to read content from application/json tiddlers, but writing more than 1 level deep is not part of the TW core yet.
So plugins will be needed if you want to do so. … Or create your JSON tiddlers from the command line and import them to TW.
this is a sad gap, I hope can it be added, ideally for the next release. Gaps like this can cause users waste hours trying to find the what should be a complementary feature only to discover its missing.
A similar example is allowing convert to Unix time but not from Unix time to TW serial date.
Are you asking how to extract data from a JSON object into tiddler fields? The new JSON operators can accomplish that.
Or are you asking for techniques for generating JSON? That’s something I’d like to add to the core, but there are already a variety of techniques available. One simple approach is to treat them like we do stylesheets. For example:
And my usage is to export the whole wiki as an array of game JSON data! So I hope when I getTiddler, the transportation field becomes a JSON object directly.
The YAML library for JS is super heavy weight in terms of file size and IMO it’s as error prone to manually create as JSON. It replaces different types of braces with different type of indentation and other chars.
So in terms of manual errors IMO it’s the same amount of work to maintain
Actually, I don’t mean manually editing yaml inside .tid file, I mean storing it that way automatically by the tw core. So when loading it, tw core knows it is a JSON object instead of a string with brackets.
So when I export tiddlers as JSON, it will become nested json, instead of currently a flat json with stringified value.
And I can provide a nested field value editor input for it.
Unfortunately, the last time I looked, the smallest YAML parser I could find was about 80KB, so I don’t think that it is appropriate for the core. But there’s nothing to stop somebody making a plugin that adds support for YAML encoded data tiddlers. I’m pretty sure it can be done already, but if not I’d be happy to see core changes to make it happen.
There was an early version with those restrictions. By the time we merged them, the JSON operators operate on filter values, and so they can be used with variables or any other text source.
That’s correct. In order to be able to automatically parse them into JSON objects we’d have to have a way of knowing which fields contain JSON. I don’t think it’s a problem; there’s some inefficiency but we already suffer from that with the way that plugins are encoded.