[uf-discuss] Generically converting JSON to POSH

Toby A Inkster mail at tobyinkster.co.uk
Mon Jul 14 01:52:28 PDT 2008


Nirmal Patel wrote:

> I am converting arrays into ordered lists and dictionaries into
> unordered lists where each list item has a classname that is equal to
> the key in the key/value pair.

Looks quite good. Personally I'd have converted JSON objects into  
definition lists using DT for the key and DD for the value though.  
Then perhaps add the key to the class of each *as well*. So, for  
instance:

{
   "key1" : "value1" ,
   "key2" : "value2"
}

becomes:

<dl class="json-object">
   <dt class="key1">key1</dt>
   <dd class="key1">value1</dt>
   <dt class="key2">key2</dt>
   <dd class="key2">value2</dt>
</dl>

Which should be more flexible with regards to styling, and probably  
more useful when looked at without CSS. If you happen to like the  
unordered list look, then:

dl.json-object dt { display: none; }
dl.json-object dd { list-style-type: circle; }

However, have you considered what happens when the object keys  
contain whitespace characters? e.g.

{
   "some key" : "some value"
}

-- 
Toby A Inkster
<mailto:mail at tobyinkster.co.uk>
<http://tobyinkster.co.uk>





More information about the microformats-discuss mailing list