I need help accessing properties of JSON data tiddler

I am a new user and am having trouble accessing data in JSON tiddler “ConfigY” with type = “application/json”. I tried 8 different retrieval scenarios all contained in the $set widget that initializes jsondata. Some work and most do not. I am missing something obvious. I would greatly appreciate suggestions of what I am doing wrong for the scenarios that don’t work (#4,6,7,8).
Thank you,
-Dan

Here is ConfigY

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

Here are the results of the 8 scenarios:

  1. Accessing key=a of json tiddler with transclusion wikitext:

<$set name="jsondata" value={{ConfigY}}>
{{ConfigY##a}}

<$set>

Preview:

Apple

works showing JSON object is recognized


2. Contents of jsondata - triple curly bracket filter syntax:
<$set name="jsondata" value={{ConfigY}}>

{{{ [<jsondata>] }}}

<$set>

Preview:

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

Seems to work


  1. Contents of jsondata - variable syntax:
<$set name="jsondata" value={{ConfigY}}>
<<jsondata>>
<$set>

Preview:

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

Seems to work


4. Retrieve access key=a using wikitext variable syntax:
<$set name="jsondata" value={{ConfigY}}>
<<jsondata##a>>
<$set>

Does not work


5. Retrieve access key=a using view widget:
<$set name="jsondata" value={{ConfigY}}>
<$view tiddler="ConfigY" index=a />
<$set>

Preview:

Apple

Works


6. Retrieve access key=a with jsonget - filter syntax:
<$set name="jsondata" value={{ConfigY}}>
{{{ [<jsondata>jsonget[a]] }}}
<$set>

Preview shows nothing. Does not work


7. Try to get indices with jsonindexes using filter syntax:
<$set name="jsondata" value={{ConfigY}}>
{{{ [<jsondata>jsonindexes[]] }}}
<$set>

Preview is blank. Does not work


8. Try to extract with jsonextract using filter syntax:
<$set name="jsondata" value={{ConfigY}}>
{{{ [<jsondata>jsonextract[]] }}}
<$set>

Preview is blank. Does not work

1 Like

Are your sure about using a version with support for getting data from JSON tiddler?

In the point 4, if you create a variable, you have to use its name, you can’t use extras in its call.

1 Like

The fact that 6, 7 & 8 don’t work suggests that you might be using a version of TiddlyWiki that does not include the JSON operators. They were only added in v5.2.4.

The ## syntax for accessing indexes only works when transcluding tiddlers, not when transcluding variables.

This one does work in my tests, returning “Apple”

This one works in my tests, returning “abcd”

This one works in my tests, returning the following:

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

One other thing to check – did you give the tiddler “ConfigY” the type “application/json”?

Just checked and I am running 5.2.3. I will have to see how far behind I am and update.
Jeremy R points out that some features that aren;t working for me require at least 5.2.4.
Thank you for your help.
-Dan

yes. I have that right :slight_smile:

Turns out i’m using 5.2.3. I will upgrade and see if that fixes the cases that should work.

I tried to edit and add that statement to the reply below but “Save Edits” seems not to have saved the change.

BTW, thank you for creating TW. I am using it with node.js and think it’s a work of art. Incredibly clever and innovative new paradigm for web development and full of great features too numerous to list. Obviously i am still trying to get my head around the language.

-Dan

Update: I upgraded to 5.2.5 and all is now working. Thanks again.

Terrific, thank you @dfh much appreciated.