What should I do to implement the transclusion to show a JSON value in a list?

I have some tiddlers in which some things have been recorded. I have used several fields to express the different aspects of those things for every tiddler. To ensure consistency, I have defined some data tiddlers. For example, the content of one is as follows:

00: Unknown
01: Level1
02: Level2
03: Level3
99: Unsuitable

The Tiddler has the name LevelCode.

After I finished editing the LevelCode Tiddler, the sentence below worked well.
{{LevelCode##01}}

Then, I needed to show a list of things, so I drew up a sentence like this:

<$list filter="[tag[Things]]" counter="counter">
<div>
 <<counter>> , ''<$text text={{{[<currentTiddler>get[title]]}}}/>'' , ''<$text text={{{[<currentTiddler>get[t.level]]}}}/>'' .
</div>
</$list>

The output is like this:

1 , 2023001 , 01 .
2 , 2023002 , 02 .
3 , 2023003 , 01 .
4 , 2023004 , 03 .

All things look well until now.

The problem is that in the given output, the meaning of level needs to be translated by the reader. It is obviously not friendly to the reader. Thus, I tried to use some JSON operators to handle this issue. When I used jsonget operator, I found that the dictionary tiddler was not supported (maybe my wrong use). So I transformed the dictionary Tiddler to JSON toddler, like this:

{
"00": "Unknown",
"01": "Level1",
"02": "Level2",
"03": "Level3",
"99": "Unsuitable"
}

The sentence {{LevelCodeJson##01}} worked also.

Some sentences worked well, as follows:

<$set name="myVariable" tiddler="LevelCodeJson" >
<$text text=<<myVariable>>/>
<$text text={{{ [<myVariable>jsonget[03]] }}} />
</$set>

The results were:
{ “00”: “Unknown”, “01”: “Level1”, “02”: “Level2”, “03”: “Level3”, “99”: “Unsuitable” }Level3

My problem is that some sentences do not work because the key recorded in the field “t.level” in the Tiddlers tagged “Things” cannot be transcluded correctly, i.e., the sentences below do not work as expected.

<$list filter="[tag[Things]]" counter="counter">
<div>
| <<counter>> |  ''<$text text={{{[<currentTiddler>get[title]]}}}/>''  | ''<$text text={{{[<currentTiddler>get[t.level]]}}}/>'' | {{LevelCodeJson##<$transclude $field="t.level"/>}} | <$text text={{{ [<myVariable>jsonget[<$transclude $field="t.level"/>]] }}} /> |
</div>
</$list>

In my understanding, either {{LevelCodeJson##<$transclude $field="t.level"/>}} or <$text text={{{ [<myVariable>jsonget[<$transclude $field="t.level"/>]] }}} /> does not work. Namely, anything is not shown in the output.

What’s wrong? How to use some means to show the value rather than the key(index) in the output so that the result is shown like this?

1 2023001 Level1
2 2023002 Level2
3 2023003 Level1
4 2023004 Level3

When posting code here please wrap in single or tripple back ticks and use the </> button.

In your code you cant mix use of short forms of transclude {} and long forms $transclude. The long form is the most versatile.

Try this:

<table>
<$list filter="[tag[Things]]" counter="counter">
   <$let level={{{[<currentTiddler>get[t.level]]}}}>
   <tr>
      <td><<counter>></td>
      <td>''<$text text=<<currentTiddler>>/>''</td>
      <td>''<$text text={{{[[LevelCode]getindex<level>]}}}/>''</td>
   </tr>
   </$let>
</$list>
</table>

Notes:

  • Your initial “LevelCode” tiddler doesn’t need to be JSON, but does need it’s type field set to application/x-tiddler-dictionary so that you can use the getindex<level> filter operator.
  • When table rows are generated within a $list widget, you should use HTML standard table syntax rather than the wikitext vertical-bar syntax (which handles simple static tables just fine, but not so much for tables with generated rows).
  • Note the use of <$let level=...> to fetch the tiddler’s t.level field value as a variable. This allows you to then use that variable as the operand for the getindex filter to retrieve the corresponding LevelCode text.

enjoy,
-e

Thanks a lot. I will abide by the rule when I post code next time.

I appreciate that you gave me such a feasible scheme and some hints on how to use wiki supported with HTML. Awesome!

I am trying to use JSON in Tiddlywiki to deal with the relationship between some things. For example, I define a Tiddler named Action like this:

{
"1.1": "Get up",
"1.2": "Breakfast",
"1.3": "Go to office",
"1.4": "Analzing requirement",
"1.5": "Lunch",
"1.6": "Nap",
"1.7": "Discussion",
"1.8": "Meeting",
"1.9": "Developing prototype",
"1.10": "Go home",
"1.11": "Supper",
"1.12": "Reading reference material",
"1.13": "Watching TV",
"1.14": "Go bed"
}

I expect two goals could be achieved.

Firstly, the content could be shown without the signs of JSON, like this:

1.1 Get up
1.2 Breakfast
1.3 Go to office
1.4 Analzing requirement
1.5 Lunch
1.6 Nap
1.7 Discussion
1.8 Meeting
1.9 Developing prototype
1.10 Go home
1.11 Supper
1.12 Reading reference material
1.13 Watching TV
1.14 Go bed

It would be better if some wiki or HTML or CSS command could be used to make the content look good.

Otherwise, for the same content, there are two Tiddlers that might need to be set, and the content needs to be synchronous manually.

Secondly, the content in the JSON Tiddler could be referred to as a field.

Then, by using some means such as a table, even the TiddleMap, the relationship could be pointed out. For example,

Person1 - Go to office

This goal might be achieved by the way that you teach me, and I will try it later.

I personally consider that the power of JSON can promote the effect of the use of TiddlyWiki a lot.

Thanks again.

Best regards,

Kuan

The following only goes part of the way, but may help.

This is you current data in a tiddler with type=application/json

{
"1.01": "Get up",
"1.02": "Breakfast",
"1.03": "Go to office",
"1.04": "Analzing requirement",
"1.05": "Lunch",
"1.06": "Nap",
"1.07": "Discussion",
"1.08": "Meeting",
"1.09": "Developing prototype",
"1.10": "Go home",
"1.11": "Supper",
"1.12": "Reading reference material",
"1.13": "Watching TV",
"1.14": "Go bed"
}

Notice the placement of zeros in the decimal number

You can use;

<$list filter="[[Data]indexes[]]" variable=index>
   <<index>> <$text text={{{ [[Data]getindex<index>] }}}/><br>
</$list>

A data Dictionary

If you remove the { and } from your data tiddler and give it the type application/x-tiddler-dictionary you can list the indexes (also called property/properties) within it by;

<$list filter="[[Data]indexes[]]">

</$list>

And to show both;

<$list filter="[[Data]indexes[]]" variable=index>
   <<index>> {{{ [[Data]getindex<index>] }}}<br>
</$list>

But you will notice neither the key or the value needs to be wrapped in quotes, only that they are divided by : for a dictionary tiddler.

So you could use;

1.01 : Get up
1.02 : Breakfast
1.03 : Go to office
1.04 : Analzing requirement
1.05 : Lunch
1.06 : Nap
1.07 : Discussion
1.08 : Meeting
1.09 : Developing prototype
1.10 : Go home
1.11 : Supper
1.12 : Reading reference material
1.13 : Watching TV
1.14 : Go bed

And the same $list as above

  • What do you mean?

Something like this?

<table>
<tr><th>Item</th><th>Action</th></tr>
<$list filter="[[Data]indexes[]]" variable=index>
   <tr><td><<index>></td><td><$text text={{{ [[Data]getindex<index>] }}}/></td></tr>
</$list>
</table>

Many thanks for your answer.

I am afraid I have not expressed what I want to ask clearly.

In the case of the JSON Tiddler presents a comprehensive rule set, like this:

The name of the Tiddler is RuleA, and the contents are:

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

Could the method that you guided me work?

I haven’t tried them. ​I would appreciate it if you would like to give me some hints on it.

I can’t help too much because I have not written much for reading JSON but there are some improvements coming in the prerelease including a new jsonset operator

But I can see that you will need a compound key as found in the example above from here such as [<jsondata>jsonget[d],[f],[0]]

  • keep in mind if you write nested lists to find the key you can use variables to reference each leaf in such a tree [<jsondata>jsonget<a>,<b>,<c>] where a=d, b=f, c=0

To try the examples in the documentation to learn about them try

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

# `[<jsondata>jsonget[a]]` {{{ [<jsondata>jsonget[a]] }}} --> "one"
# `[<jsondata>jsonget[d],[f],[0]]`  {{{ [<jsondata>jsonget[d],[f],[0]]  }}}

etc...

I really appreciate it.

Welcome to talk.tiddlywiki, @likuan61!

I don’t know how you’re editing the tiddlers that use these values as fields, but if you’re interested, you can make the entry box into a dropdown that shows "Unknown", "Level1", "Level2", "Level3", and "Unsuitable", but sets the value to "00", "01", "02", "03", or "99".

The technique is documented in Customizing EditTemplate field rendering.