How to access JSON data?

Guess I have one of my dull moments again…

TW version: 5.3.0-prerelease (commit: 9b59dff275e996ea5fa602912e2ff670d50e5b89)

Following the solution posted by Jeremy here: Accessing JSON data tiddlers

However that does not result in any output in tiddlerB:

# tiddlerA.json
{
	"caption": "Lame pasta",
	"hide-body": "yes",
	"text": "{\"ingredients\":{\"a9a0pu\":\"400\"},\"steps\":\"# Boil water\n# Add {{a9a0pu##name}}\"}",
	"title": "tiddlerA",
	"type": "application/json"
}
# tiddlerB
<$list filter="[[tiddlerA]get[text]jsonget[steps]]">

<<currentTiddler>> # <- would expect to see the raw string

</$list>

Hi @tjout I created “tiddlerA” with the content from the text field with the escaping removed:

{"ingredients":{"a9a0pu":"400"},"steps":"# Boil water\n# Add {{a9a0pu##name}}"}

Then in another tiddler I typed your tiddlerB content:

<$list filter="[[tiddlerA]get[text]jsonget[steps]]">

<<currentTiddler>> # <- would expect to see the raw string

</$list>

The result was:

# Boil water # Add # <- would expect to see the raw string

There are two issues: the fact that the # markers are not interpreted as a numbered list is because the text is parsed in inline mode. This can be fixed by removing the text after the macro call:

<$list filter="[[tiddlerA]get[text]jsonget[steps]]">

<<currentTiddler>>

</$list>

The other issue, of course, is that the tiddler “a9a0pu” doesn’t exist, and so the transclusion is blank.

I’m not sure why you were seeing different results. Here’s a share link with the test data I used.

2 Likes

Hi @jeremyruston thank you for taking the time, I really appreciate attention from BDFL :wink:

I tried a few different constructions and it seems that for some reason the filter would wrap the result in another pair of [] which causes jsonget[steps] to not return anything because the data passed to it looks like this: [{"ingredients":..., "steps":...}].

I don’t know if I messed something up when setting up my directory structure but I went ahead and rebuild the wiki from the same commit and now it works like your example. Guess it was too late for me yesterday…

Thank you for confirming my approach was sound!

Great, thanks @tjout happy to help!