Search code examples
jsondata-structuresmicroformats

JSON and Microformats


I'm looking for opinions on whether microformats should be used to name JSON elements. For instance, there is a microformat for physical addresses, that looks like this:

<div class="adr">
    <div class="street-address">665 3rd St.</div>
    <div class="extended-address">Suite 207</div>
    <span class="locality">San Francisco</span>,
    <span class="region">CA</span>
    <span class="postal-code">94107</span>
    <div class="country-name">U.S.A.</div>
</div>

There is a document available on using JSON and Microformats. The information above could be represented as JSON data like this:

"adr": {
    "street-address":"665 3rd St.",
    "extended-address":"Suite 207",
    "locality":"San Fransicso",
    "region":"CA",
    "postal-code":"94107",
    "country-name":"U.S.A."
},

The issue I have with this is that I'd like my JSON data to be as lightweight as possible, but still human readable. While still supporting international addresses, I would prefer something like this:

"address": {
    "street":"665 3rd St.",
    "extended":"Suite 207",
    "locality":"San Fransicso",
    "region":"CA",
    "code":"94107",
    "country":"U.S.A."
},

If I'm designing a new JSON API right now, does it make sense to use microformats from the start? Or should I not really worry about it? Is there some other standard that is more specific to JSON that I should look at?


Solution

  • This comes down to a matter of personal choice for a simple reason. The difference using your sample data is approx. 192 bits of data. At this point your process/transfer difference is negligible.

    If it's an internal API then your suggested method is more than adequate. It easily identifies each section tersely while still being descriptive. However, if the API is something that you plan on opening up to the public, I would suggest the staying with the micro-format.