A question about JSON and META files

77 views
Skip to first unread message

mauloop

unread,
Jan 7, 2019, 1:24:03 PM1/7/19
to TiddlyWiki
Hi sirs, and wish you a Happy New Year (a little bit late for greetings but this is my first post in 2019).

Does anyone know if there is a way to force Tiddlywiki (running on Node.js) to save .JSON + .JSON.META files instead of a single .TID file, when creating tiddlers with type = "application/json"?

I need to create JSON files which in turns should feed another application, so I'd like that Tiddlywiki related stuff was saved apart, since it is not useful for the receiving app.

Thanks in advance,

)+(
Message has been deleted

mauloop

unread,
Jan 8, 2019, 4:45:25 AM1/8/19
to TiddlyWiki
As a workaround I created a custom exporter:

title: $:/.mau/exporters/json
description: Export text as JSON
extension: .json

\define renderContent()
{{{ $(exportFilter)$ +[limit[1]] ||$:/.mau/templates/json}}}
\end
<$importvariables filter="[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]"><<renderContent>></$importvariables>

title: $:/.mau/templates/json

<$view field="text" format="plainwikified" />

It works, but it is not exactly what I was looking for.
  • First, it is not autonomous. It requires the user to click a button to trigger the export.
  • It is not exactly a json exporter, but a "text only" exporter. It exports just the text field, despite its content. Applied to an "application/json" tiddler it actually creates a JSON file.
I use this button to trigger the export:

title: $:/.mau/json-export-button

<$button class="tc-btn-invisible tc-tiddlylink">
{{$:/core/images/export-button}} Export text as JSON
<$action-sendmessage $message="tm-download-file" $param="$:/.mau/exporters/json" exportFilter="""[[sample.json]]""" filename="sample.json"/>
</$button>

And this is the sample.json I used to test the exporter:

title: sample.json
type: application/json

{
    "album": "The Dark Side of the Moon",
    "artist": "Pink Floyd",
    "year": "1973",
    "tracks": [
        "Speak to Me",
        "Breathe",
        "On the Run",
        "Time",
        "The Great Gig in the Sky",
        "Money",
        "Us and Them",
        "Any Colour You Like",
        "Brain Damage",
        "Eclipse"
    ]
}

Happy to share this workaround with the community. Still searching for a way to save "application/json" tiddler as .JSON + .JSON.META. Any idea? Maybe some options in tiddlywiki.info?

Thanks,

)+(

TonyM

unread,
Jan 8, 2019, 8:28:53 PM1/8/19
to TiddlyWiki
Mauloop,

Thanks so much for Sharing back to the community. Using templates to create the content one wants to save is a key pattern in TiddlyWiki. 

When people learn how to do this and build their own exporters I believe they are greatly empowered.

Something I discovered recently is, if you craft a tiddler to look exactly as you would want it to save, you can open that tiddler in New Window, use the browsers print and print to a Generic/text file printer. 
Then rename the filename to save to the required extension and print. 

This is a quick way of exporting something and not being restricted to registered file types.

Regards
Tony
Reply all
Reply to author
Forward
0 new messages