Rendering json or html encoded string from field

Hello,

Tiddlywiki is incredible : versatile, efficient, fast and a sustainable solution, saving a lot of energy: no backend code, no remote DB, no trouble… I definitively love it even if I’m still at the beginning of my learning journey.

When I try to render data extracted from json retrieved from a tiddler, I can’t get rid of quotes and I can’t figure on which filter I could rely on to properly render encoded field.

considering a tiddler with a jsondata field containing
[{ “author”: “John Doe”, “date”: “202310161515”, “comment”: “This was so “nice”…\nto just try…”},{ “author”: “Paul”, “date”: “202310161518”, “comment”: “”}]

Once processed, it renders as:
image

Why is each value enclosed by quotes ? how to improve my tiddler to manage properly the conversion (author as html, comment as json sting and date) ?

<$list filter="[<currentTiddler>get[jsondata]jsonindexes[]]" variable="index">

<$text text={{{ [<currentTiddler>get[jsondata]jsonextract<index>jsonextract[author]] }}}/> on 
<$text text={{{ [<currentTiddler>get[jsondata]jsonextract<index>jsonextract[date]] }}}/> said :
<$text text={{{ [<currentTiddler>get[jsondata]jsonextract<index>,[comment]] }}}/>

</$list>

Best regards,
Guilhem
PS : Surprisingly, thanks to tiddlywiki my confidence in my coding skill increased when I tried to get answers from chatGPT: so many excuses and so many wrong answers :smile:

1 Like

Hello Guilhem and welcome to the forum!

I think to extract the actual data, and not a string formatted as JSON, you want to use jsonget for the last bit. But I could be wrong.

Here’s the version I came up with. I’m using the wikify widget on the author field to deal with the embedded HTML codes. And then jsonget on all the other fields.

<$list filter="[<currentTiddler>get[jsondata]jsonindexes[]]" variable="index">

<$wikify text={{{ [<currentTiddler>get[jsondata]jsonextract<index>jsonget[author]] }}} 
 mode="inline" output="text" name="author"><<author>></$wikify>    on 
<$text text={{{ [<currentTiddler>get[jsondata]jsonextract<index>jsonget[date]] }}}/> said :
<$text text={{{ [<currentTiddler>get[jsondata]jsonextract<index>jsonget[comment]] }}}/>

</$list>

Here’s the data I used, which might be a little different from yours:

[{ "author": "John&nbsp;Doe", "date": "202310161515", "comment": "This was so 'nice'…\nto just try…"},{ "author": "Paul", "date": "202310161518", "comment": ""}]

And here’s my output:

image

Note that you should put things like JSON data in code blocks in the forum because otherwise Discourse will mangle the quote marks into “pretty” quotes – which are no longer valid JSON

Hope this helps!

1 Like

Hi Mark,

This definitively helps and makes sense. Thanks a lot !

Best regards,
G.

PS Maybe could we propose a slighy improvement in documentation on this ?

replacing [<jsondata>jsonget[a]] --> "one"
by [<jsondata>jsonget[a]] --> one

while jsonextract would remain

[<jsondata>jsonextract[a]] --> "one"

or for sick minds, leaving jsonget as is and changing only jsonextract to

[<jsondata>jsonextract[a]] --> "\"one\""
1 Like