intfiction.org

The Interactive Fiction Community Forum
It is currently Tue May 21, 2013 10:52 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: JSON support in Inform?
PostPosted: Mon Mar 26, 2012 2:31 am 
Offline
User avatar

Joined: Wed Nov 30, 2011 2:43 am
Posts: 212
Hi, has anybody tried to do JSON serialization in Inform? Or XML, or (shudder) YAML, or anything like that.

I couldn't find any extensions for it but maybe somebody is sitting on some code?

I haven't really thought about it that much, I was just thinking maybe key/value pairs in tables could be quite simple to do, maybe using Jesse McGrew's dynamic memory extensions. But maybe it's even possible to do "real" JSON serialization, maybe using an intermediary json-ready format in Inform?

I was thinking to/from files but if it's possible to hook it up with http rest requests that's even cooler.

The number of maybes in this post reflects how much though I've given to this.


Top
 Profile Send private message  
 
PostPosted: Tue Mar 27, 2012 10:11 am 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 963
It would be possible, but it may not be the best serialisation format. Without specific use cases it would be hard to say it's worth the effort.

Btw, there's no reason why you couldn't output a dynamically generated file with Inform's standard table serialisation format over HTTP. Except that there's no easy way (yet) to do HTTP in Inform.


Top
 Profile Send private message  
 
PostPosted: Tue Mar 27, 2012 4:41 pm 
Offline

Joined: Wed Jan 19, 2011 3:36 pm
Posts: 99
The short answer is "not in I7". I7 files begin like this:
Code:
* //IFID// leafname


XML does not. Any file that I7 can read will not pass any XML validation, and no valid XML file will be readable by I7. You might be able to cook something up with I6, however.

More generally, most configuration file formats won't tolerate "garbage" at the beginning.

Also, I7 provides support for "binary" files; I'm not sure if this header applies to them, and if not, XML would hypothetically be possible.

But there's another major roadblock: the only way to grab a file's text is all at once, and that may not be suitable for our purposes.

At any rate, I'd recommend YAML instead of XML since it has stricter rules about where and how whitespace may occur, and is generally simpler.


Top
 Profile Send private message  
 
PostPosted: Fri May 11, 2012 12:11 pm 
Offline

Joined: Wed Jun 22, 2011 1:03 am
Posts: 21
heres something parsingof the json that firefox generates by "backing up bookmarks":
https://github.com/koo5/internetmarks

heres some outputing of normal files...
https://github.com/koo5/sitegen/blob/ma ... process.py

:!: hopefully helpful along the way, nothing else.


Top
 Profile Send private message  
 
PostPosted: Thu May 17, 2012 11:45 pm 
Offline

Joined: Sat May 03, 2008 11:32 pm
Posts: 156
NYKevin wrote:
The short answer is "not in I7". I7 files begin like this:
Code:
* //IFID// leafname


XML does not. Any file that I7 can read will not pass any XML validation, and no valid XML file will be readable by I7. You might be able to cook something up with I6, however.

To be clear, this limitation applies to plain, off-the-shelf I7. You could certainly write an I7 extension that uses Glk I/O calls to bypass limitations like needing a header, slurping the entire file contents at once, etc. It's just that the extension would have to include some embedded I6 code.


Top
 Profile Send private message  
 
PostPosted: Fri May 18, 2012 2:15 am 
Offline
User avatar

Joined: Wed Nov 30, 2011 2:43 am
Posts: 212
vaporware wrote:
To be clear, this limitation applies to plain, off-the-shelf I7. You could certainly write an I7 extension that uses Glk I/O calls to bypass limitations like needing a header, slurping the entire file contents at once, etc. It's just that the extension would have to include some embedded I6 code.


Ok, that's helpful. I hadn't looked into this at all. So you can just call methods in the glk api straight from Inform6 (if you're using glulx, of course)? Cool.

Maybe I'm an Inform6 guy after all...

I don't think I'll be digging into this right now, but thanks for pointing in this direction!


Top
 Profile Send private message  
 
PostPosted: Sat May 19, 2012 4:58 pm 
Offline
User avatar

Joined: Thu Feb 11, 2010 1:51 pm
Posts: 198
Location: Chicago, Illinois, USA
peterorme wrote:
Hi, has anybody tried to do JSON serialization in Inform? Or XML, or (shudder) YAML, or anything like that.


FyreVM, Zifmia, and the coming new Textfyre portal uses JSON, but in this case, the JSON is simply what is returned from the Zifmia REST calls. These can be transmitted in any format really.

Using REST and JSON is very convenient for a client/server engine.

David C.
textfyre.com


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group