How to write nested JSON structure in tiddler fields, like Array or Object

No, jsontiddler Macro will still return stringified field value:

I think this basically means I need to write a plugin for the process of

  1. inputting json using the extended form UI
  2. using JSON filters we already have to write filters in the wiki
  3. exporting JSON based on a schema,that will tells which field contains JSON content.

And in the tiddler, JSON Object fields will still keep being stringified.

Tiddler field values are always strings. Internally, the “list” field is modelled as an array of strings. It sounds like you want tiddlers to be stored such that the field value is arbitrary JSON. That would be a deep change to the core.

Could you go back to what you’re trying to do? If I understand correctly, you want a user to be able to fill in some input boxes, and then generate a block of JSON that incorporates the values entered by the user? What’s the next step for the JSON? Do you want to export it for processing elsewhere, or POST it to an API endpoint?

I will load those JSON to a game engine, possibly by exporting tiddlers as JSON-LD to SoLiD server using solid-tiddlywiki-syncadaptor.
Then my game engine will load JSON-LD from SoLiD, and run procedural content generations scripts, just like how DrawfFortress uses its data to generate a game world dynamically.

I’m using JSON to describe all possible things in the game world, so some fields need to be arbitrary JSON to gain enough expressibility.

Hi @linonetwo it sounds like perhaps the problem is that you’re trying to reuse TiddlyWiki’s existing JSON export format. There’s a fundamental incompatibility that stops that from working: TiddlyWiki requires that fields be strings.

So, I think the workaround would be to make your own template that exports the fields you want as text within the JSON framework, as I showed above.

  • @linonetwo Not only as suggested by @jeremyruston but keep the data as a regular tiddler to maximise how you can act on and manipulate the tiddler with standard tools.
  • Then in the “your own template that exports the fields” allow “named” fields to use one form of encoding over the other.
    • The same could be done for static content that the server also publishes, so the alternate format JSON data is found at a URL.
      • I cant find my current documentation on publishing “static tiddlers” along side the interactive Node wiki, with this you need only change the template.
  • my point is keep your data in the native form and only use an alternative when needed such as at export, or publishing.
    • If you need it all the time, add a viewTemplate

In theory, any nested data structure can be represented by a scheme of property name concatenation:

{
aaa: {
     bbb: {
         ccc: 1
         ddd: true
      }
}

Can be represented as

{
"aaa'bbb'ccc": 1,
"aaa'bbb'ddd": true
}
1 Like

Yes, although no single schema like that can capture every possible JS object, since whatever character (or string of characters) is used as a separator could also be used in a property name:

const myObject = {
    aaa: {
        bbb: {
            ccc: 1
       },
       ddd: true,
       "bbb'ccc": 42
    },
    "aaa'bbb'ccc": "huh?"
}
myObject.aaa.bbb.ccc     //=> 1
myObject.add.bbb.ddd     //=> true
myObject.aaa["bbb'ccc"]  //=> 42
myObject["aaa'bbb'ccc"]  //=> "huh?"

If you choose an array of strings instead, you don’t have this issue:

const flattenedObject = [
  [["aaa"], ["bbb"], ["ccc"]], 1],
  [["aaa"], ["bbb"], ["ddd"]], true]
]

But I’m not sure how much relevance any of this has for Tiddlywiki.

Right. But.

IMHo “The JS-Side” (pure, not so mediated) may well have, now, right now, some possible/probable relevance to TW steps on.

Why? It’s logic is a reasonable semblance of cognitive intuitism (=subset of living thinking meat).
Since TW inheres in an agnostic—not a gridded perfunctory partialised performant—logic, JS can help (with bright sparks involved) keep it clean.

Just a wet brain comment
J.

Finding threads like this one, is one of the main reasons I like the serendipitous nature of this forum, as recently I was thinking that having nested JSON data in a tiddler (maybe as a plugin) is a necessity I have found time and again for a more versatile representation of my information needs in TiddlyWiki. And somehow it resurfaced again once I saw @linonetwo’s TidSeq theme with its Mindmap Elixir plugin that I hope to test on this year’s end holidays, as I would like to use tiddlers in several mind maps (still a fuzzy idea, but seems that the ability to produce and maybe store JSON from Tiddlers could be important in that scenario).

Once I have a clearer picture, I’ll be sharing with the community my explorations/inquiries.

Cheers,

1 Like