Question: How to render JSON instead of HTML and save the results to a JSON file

I would like to know if, like using node tittdlywiki to export json

tiddlywiki  --load ${INDEX} \
                    --output /tmp/ \
                    --render '.' 'exportpdf.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[pdf]]'

Is there a way to make the same with online TW, changing renderer? “$:/core/templates/exporters/JsonFile”

For example, is it possible to have a json file (no html) output from that address? https://tiddlywiki.com/#:[tag[Features]]

Hi, There is a very similar thread at: Using TW5 as CMS: Render JSON with HTML-Tags instead of Wikitext, which conatains several template sugestions. It should be possible to adjust those mechanisms for your usecase.

If I understand this line right. You would like to use TW as an API replacement that returns a JSON array instead of a rendered wiki. Is that right?

Just to build on:

https://cjveniot.neocities.org/TiddlyWiki%20Projects/TW_JSONIFY.html?filter=[tag[Features]]#:JSONIFY

Yeah, the html link I had put here wasn’t working. I guess we have to copy the link above into the browser URL field. I’m thinking Talk can’t handle the parameters.

Pretty cool way of providing links to groups of tiddlers as JSON “packages”…

Just because I don’t like how the URL is showing in Talk, here’s a screenshot of what the URL looks like in my browser:

Already Node tiddlywiki can publish simultaneously to the interactive wiki, static html tiddlers at their own address, I don’t see why you could not also do the same for selected JSON tiddlers so they will just exist, and be dynamically updated with changes in the interactive wiki.

This is it.

Same output as, https://cjveniot.neocities.org/TiddlyWiki%20Projects/TW_JSONIFY.html?filter=[tag[Features]]#:JSONIFY but with json alone.

Don’t know if it’s possible. From core, it is like allow saving of specific part of whole html? Kind of “export all displayed tiddlers” or such
exporttiddler

I am actually building an IPFS distributed App with it, tiddlywiki command line is nice, and we could build an API with it. Now an “http json API mode” would be great

OK. … But i think, that’s a problem. tiddlywiki.com actually serves a single-page-app that renders the HTML UI client side. So it’s a static “index.html” file served from GitHub. – No Node.js server involved.

It would be possible to load a SPA and create an output that looks like a JSON reply from a server but it would still load the whole app that’s needed to create the JSON output clientside. I’m not sure, if that’s what you want.

1 Like

Ok, I’ve updated my sample (treating that TiddlyWiki instance as if it were a server) as per my understanding of what you’ve described.

Same link as before:

https://cjveniot.neocities.org/TiddlyWiki%20Projects/TW_JSONIFY.html?filter=[tag[Features]]#:JSONIFY

That TiddlyWiki instance I’m using is a copy of tiddlywiki.com, with two tiny tiddlers added. Those two tiddlers in attached json file.

(Interesting: the url with parameters, the JSON “view” loads up fairly quickly; the URL to open the TiddlyWiki instance as normal, slow as molasses.)

tiddlers (2).json (1.3 KB)

Screenshot:

It’s not well documented, but Tiddlyhost can do something like this:

Here are some example urls to show how it works:

You can also access “.tid” files, and you can pick out a single tiddler’s json using the title field, e.g:

Update: I added some documentation here.

2 Likes

Sure. It must act like you said.
TW with IPFS attachments are “low size”, so this overload is not a problem.

Your approach really getting close…
And yes !

is exactly the output, missing filters maybe. But this is a good option.
I still do not understood how you made your TW act like that, but I am really interested if you can explain.

Let me know what’s missing and maybe I can add it.

:JSONIFY output is only visual, downloading it (using curl) is still whole html page. It cannot be used as json API.

@simon links are producing the expected output, but seems not generated through TW index.html… Needs server side code?

Side Note: it might be worth changing the title for this discussion to something like “How to render JSON instead of HTML and save the results to a JSON file”

Save button added. (Reference: Saving HTML5 textarea contents to file)

1 Like

As I wrote. If you want to use it with curl, there needs to be a server side implementation. That’s what Simons links does. It’s the server, that returns the JSON data instead of sending an HTML file

I do not believe there is a workaround for this when using single file TiddlyWiki.

Correct. TiddlyWikis hosted at TiddlyHost allow fetching data via JSON and this is a feature added by means of server side code.

Where is my mind !
Of course. The html page has to be parsed and interpreted.
At best, would need chromium as client, but json API needs server side.

You are right. Not finding “edit title” to do so…


Thanks for helping me to explore that “dead hole” with me :wink:
Community is really great! :blush:

So I get back with using nodejs TW CLI / APIfication in an IPFS swarm.


You were right,
This discussion is related to my quest. Making TW json’s available to other front end Apps. I do it by extracting json using tiddlywiki CLI.

As mentioned above, it’s server-side, hence it’s not TiddlyWiki producing the output. Relevant (ruby) code here.

I cannot code ruby yet, but I realize that we are making something close to tiddlyhost.

The project i am participating is to reproduce “Scuttlebut protocol” along with IPFS keys chained through a “Web of Trust” mapping.

Our prototype is now using TW to share tiddlers and data among related friends using replication of tags in common. Most of dev team is in France, and we’re using https://monnaie-libre.fr as crypto currency. I am now building the API to play a kind of “adventure crafting game”. If it makes you curious, feel free to contact me

1 Like