Json Index separation

Hey,
I’m struggling with the index in JSON. Here is an example from the documentation:

{
    "a": "one",
    "b": "",
    "c": "three",
    "d": {
        "e": "four",
        "f": [
            "five",
            "six",
            true,
            false,
            null
        ],
        "g": {
            "x": "max",
            "y": "may",
            "z": "maize"
        }
    }
}

How can I transclude the value of index “e”? I can’t find it in the documentation. Gemini suggests

<$transclude tiddler="test.json" index="d.e"/>

But that seems to be wrong.

Thank you in advance!

Use the jsonget Operator, like this:

{{{ [[test.json]get[text]jsonget[d],[e]] }}}

Also see: JSON in TiddlyWiki and Reading data from JSON tiddlers

-e

That’s working fine, thank you. Is it possible to use the jsonset Operator in a button for example to change the value?

For a number of reasons I won’t go into here, LLM suggestions for TiddlyWiki coding are consistently bad.

In this particular case, the suggested $transclude widget usage:

<$transclude tiddler="..." index="..."/>

can only access top-level "key":"value" JSON data, like this:

{
    "a": "one",
    "b": "",
    "c": "three"
}

If a JSON tiddler contains nested objects (e.g., “d” in your example JSON), those deeper level JSON data values cannot be accessed by the $transclude widget. Note that if a JSON tiddler actually contained a top-level index named “d.e”, the $transclude syntax would be able to retrieve it, since “d.e” is just an index key that happens to contain a “.” as part of the key name.

Still… it might be a nice TWCore enhancement if the syntax suggested by Gemini actually could produce results for nested JSON objects. What would be needed is a “fallback” approach:

  • The $transclude widget processing would first attempt to find a top-level key with the specified “d.e” key name (as it currently does)
  • Then, if that doesn’t yield a result, the TWCore could split the “d.e” key name on the “.” and use each part to process the tiddler’s text content as if a [[tiddlername]get[text]jsonget[d],[e]] filter were being applied.

This might even be relatively easy to implement by simply calling on the existing jsonget filter code to perform the extended JSON processing. I have no idea if this approach would have any significant performance issues, but I think it’s worth considering.

@jeremyruston … what do you think?

-e

Sure… let’s suppose you want to input a new value and then update the JSON.

You could write something like this:

<$edit-text tiddler="$:/temp/myinput" tag=input/>
<$button>change JSON
<$action-setfield $tiddler="test.json"
   text={{{ [[test.json]get[text]jsonset[d],[e],{$:/temp/myinput}] }}}/>
</$button>

-e

2 posts were split to a new topic: Alternative Ways to Read JSON Data

As I argued from the begining of public LLM’s the key is the question you ask, and this includes preperation questions like prompting. Yes people consistently ask poor questions, and get poor answers. So yes we are getting consistently bad “LLM suggestions for TiddlyWiki coding”, primarily because it is the nieve users that do this more than others.

However I have managed to have great sucess asking the right questions and getting great code results, however I do this based on a detailed understanding of tiddlywiki so I know when such code is most likely needed and I cant use TiddlyWiki Script (I put this first)