[Ur] How to design JSON interface?

Adam Chlipala adamc at impredicative.com
Thu Dec 2 12:33:20 EST 2010


First, I now realize that I was assuming that you wanted JSON processing 
code that produced the most natural Ur types.  Obviously, in any 
language containing Core ML (which Ur/Web does), you can build a 
"dynamically typed" JSON processing library, using a universal datatype.

It will usually be nicer to produce native Ur types based on the 
"schema" of the JSON data, and I've put together a simple library, 
entirely within Ur/Web, to do just that.  The main thing that's missing 
is recursive types beyond lists; the JSON Wikipedia page that I 
consulted didn't mention anything about recursion in the parts I read, 
so maybe this isn't even a problem.  My earlier pessimism was based 
entirely on the handling of recursive types.

To use the library, you just need to add some extra lines to your 
program to map record field names to the strings to use for them in 
JSON.  Everything else is automatic, via type class resolution.

I've put my code at:
     http://adam.chlipala.net/tmp/meta.tgz

See tests/testJson.ur for a use of the library.



More information about the Ur mailing list