[TW5] Importing json files

915 views
Skip to first unread message

FrD

unread,
Jul 25, 2015, 1:30:38 PM7/25/15
to TiddlyWiki
Hi,

I'm using json tiddlers to describe the content of videos, and store the start time of the different sequences of the videos.
In order to make these tiddlers right I'm using geany, a small code editor on ubuntu.
And then instead of pasting the content of the json file in a tiddler, I'd like to import directly in the TW with the import tool.
But nothing gets imported ; it seems that the json is simply parsed and is not available.

Is there a way to import json files like other files ?

Thanks

FrD

Jed Carty

unread,
Jul 25, 2015, 2:19:16 PM7/25/15
to TiddlyWiki, soku...@gmail.com
The answer is yes. You can't just import the JSON file that you want to be stored in a tiddler though. Here is an example JSON file that would import as a JSON data tiddler:


[
   
{
       
"created": "20150725181648406",
       
"modified": "20150725181658829",
       
"title": "JSON tiddler",
       
"type": "application/json",
       
"text": "{\n    \"1\": \"2\",\n    \"3\": \"2\",\n    \"4\": \"2\",\n    \"5\": \"2\"\n}"
   
}
]

To get other examples just make json tiddlers in tiddlywiki and export them as json files.


FrD

unread,
Jul 25, 2015, 2:51:29 PM7/25/15
to TiddlyWiki, inmy...@gmail.com
Hi,

I didn't know that. Thanks.
But I don't want to have a tiddler as a json structure (with text, created, modified, ... fields).
I'd like to import something like that (it's been created in a code editor so it can be validated as a valid json object) :

{
   
"tiddler": "DVDForme103.Enchainement",
   
"description":"Enchainement complet de la forme 103 par Maître Yang Jun (DVD)",
   
"séquences":
       
[
           
{"description":"Partie 1", "type": "Déroulé", "départ": 7},
           
{"description":"Partie 2", "type": "Déroulé", "départ": 223},
           
{"description":"Partie 3", "type": "Déroulé", "départ": 754}
       
],
   
"technique":
       
{
           
"source":"DVD",
           
"durée": 1489,
           
"largeur": 640,
           
"hauteur": 480,
           
"taille": 14.67
       
}
}

 Then I'd like to import this json expression inside a tiddler, or to be precise as the text field of a tiddler. If I drag the file that contains this expression, the import tiddler appears but with no file to import.

FrD

Jed Carty

unread,
Jul 25, 2015, 3:15:56 PM7/25/15
to TiddlyWiki, soku...@gmail.com
If you take the text I gave, save it as a json file and then import it it gives you what you want, a tiddler with the json data in the text field. The example you give would be like this:

[
    {
        "text": "{\n    \"tiddler\": \"DVDForme103.Enchainement\",\n    \"description\":\"Enchainement complet de la forme 103 par Maître Yang Jun (DVD)\",\n    \"séquences\":\n        [\n            {\"description\":\"Partie 1\", \"type\": \"Déroulé\", \"départ\": 7},\n            {\"description\":\"Partie 2\", \"type\": \"Déroulé\", \"départ\": 223},\n            {\"description\":\"Partie 3\", \"type\": \"Déroulé\", \"départ\": 754}\n        ],\n    \"technique\":\n        {\n            \"source\":\"DVD\",\n            \"durée\": 1489,\n            \"largeur\": 640,\n            \"hauteur\": 480,\n            \"taille\": 14.67\n        }\n}",
        "title": "Change This Title",
        "type": "application/json"
    }
]

If you save that as a json file and import it than you will get a tiddler with your json data in the text field.

If it is going to be a tiddler than it has to have the tiddler form. Otherwise tiddlywiki can't do anything with it. When you import a json object into tiddlywiki it is parsed as a tiddler so it looks for the standard fields (title, text, etc.) so if you want to have something in the text field of a tiddler you have to create the json object you are importing in the form that tiddlywki can parse. So you would need to have at a minimum

[
{
"text": "some text here"
"title": "Change This Title",
"type": "application/json"
}
]

or tiddlywiki can't parse it. You could write your own importer, but that would probably be overkill. Replace the 'some text here' with the properly escaped text and it will import your tiddler the way you want. Perl would make it easy to take the fields you make in geany and do the proper escaping and put it into the correct format.

BJ

unread,
Jul 25, 2015, 3:23:45 PM7/25/15
to TiddlyWiki, soku...@gmail.com
there is a json editor for tw5 - but it is a bit clunky

http://bjtools.tiddlyspot.com

cheers
BJ

FrD

unread,
Jul 25, 2015, 4:17:16 PM7/25/15
to TiddlyWiki, inmy...@gmail.com
Oh I see now. I did'nt understand the first time !
So I'll have to figure out an easy way to put my json expression inside another json that tiddlywiki can process, i.e. with the relevant fields for a tiddler (text, title, type, ...)

Thanks a lot for your explanation.

FrD

FrD

unread,
Jul 25, 2015, 4:19:22 PM7/25/15
to TiddlyWiki, bugg...@gmail.com
Hi,

It looks good !
I'll give it a try.

FrD

FrD

unread,
Jul 25, 2015, 4:34:32 PM7/25/15
to TiddlyWiki, soku...@gmail.com
Hi,

Finally I've found another method :
I put /* at the beginning of the file, and */ at the end (as to enclose comments). And I delete the json extension at the end of the file name.
Then the import works as expected as the TW no longer considers it as a json file.
Then I delete /* and */ and give the tiddler the right type.
Not straightforward but ...

FrD

Le samedi 25 juillet 2015 19:30:38 UTC+2, FrD a écrit :

FrD

Danielo Rodríguez

unread,
Jul 25, 2015, 5:19:46 PM7/25/15
to TiddlyWiki
Have you tried just changing your files to txt extension?

FrD

unread,
Jul 26, 2015, 2:30:26 AM7/26/15
to TiddlyWiki, rdan...@gmail.com
Hi,

Yes it's simpler as I don't need to edit the content.
Thanks.

FrD
Reply all
Reply to author
Forward
0 new messages