JSON support in Inform?

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.

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.

The short answer is “not in I7”. I7 files begin like this:

* //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.

heres something parsingof the json that firefox generates by “backing up bookmarks”:
github.com/koo5/internetmarks

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

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

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!

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