How can I use jsonset to add property/value to a JSON tiddler?
I want a json tiddler like this
{
"toyota": {
"build": "2024",
"price": "32000"
},
"ford": {
"build": "2023",
"price": "23000"
}
}
I assume I have to use message or stfield, but no success.
pmario
August 20, 2024, 6:47pm
2
I’m not sure, what you want to achieve, but why do you make your live difficult.
Create 2 tiddlers
title: toyota
build: 2024
price: 32000
Some text if needed
title: ford
build: 2023
price: 23000
Some text if needed
You are good to go. You can use the standard UI to edit everything. You can add tags if needed. and so on, and so on
Just my thoughts
-m
Once again @pmario posted faster than me! Here is my take at it anyway:
The official jsonset documentation has numerous examples, and you can use them like this:
use a let widget to store the result of your jsonset filter in a variable
define an action procedure with one or some $action-setfield widgets
use the variable and the procedure in a $button widget
Here is a simple example to add “d” property with “jaguar” value to a json object:
\procedure myActions()
<$action-setfield $tiddler="myTiddler" $field="text" $value=<<myValue>>/>
\end
<!-- insert whatever wikitext you want here -->
<$let
object-a="""{
"a": "one",
"b": "",
"c": "three"
}"""
myValue={{{ [<object-a>jsonset[d],[Jaguar]] }}}
>
<$button actions=<<myActions>>>Try!</$button>
</$let>
To view the result, click on the button and open the new “myTiddler” tiddler.
Remember the procedure should be defined at the very beginning of the tiddler or it won’t work.
Hope this helps,
Fred
Ah, thank you Fred!
So, we need to overwrite the whole text field every time! It works.
@pmario
You are right, it is simpler -
Albeit, there are cases one has to keep them in one tiddler.
According to Modifying JSON tiddlers , the <$action-listops> widget can be used to modify attributes directly in JSON tiddlers, but I never tried this myself.
Fred