tiddlywiki5

Standard way to access a JSON tiddler from javascript


In a Tiddlywiki macro, what is the standard way to load JSON data from a JSON tiddler?

Currently, I've done this:

var my_dict = JSON.parse(this.wiki.getTiddlerText("my_json"))

Loving Tiddlywiki. Thank you!


Solution

  • Unless a better answer comes along:

    Yes, this is the way.

    But note that in some cases you'll have to use the $tw object (instead of 'this'), for example in a custom parser (such as tiddler of type 'application/javascript' and module-type: 'wikirule'):

    var my_dict = JSON.parse($tw.wiki.getTiddlerText("my_json_tiddler"))