Translating EPUB3 metadata into JSON

From the EPUB3 spec ... 

The following example shows how the complex title "The Great Cookbooks of the World: Mon premier guide de cuisson, un Mémoire. The New French Cuisine Masters, Volume Two. Special Anniversary Edition" could be classified.

<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:title id="t1" xml:lang="fr">Mon premier guide de cuisson, un Mémoire</dc:title>
    <meta refines="#t1" property="title-type">main</meta>
    <meta refines="#t1" property="display-seq">2</meta>
 
    <dc:title id="t2">The Great Cookbooks of the World</dc:title>
    <meta refines="#t2" property="title-type">collection</meta>
    <meta refines="#t2" property="display-seq">1</meta>
 
    <dc:title id="t3">The New French Cuisine Masters</dc:title>
    <meta refines="#t3" property="title-type">collection</meta>
    <meta refines="#t3" property="group-position">2</meta>
    <meta refines="#t3" property="display-seq">3</meta>
 
    <dc:title id="t4">Special Anniversary Edition</dc:title>
    <meta refines="#t4" property="title-type">edition</meta>
    <meta refines="#t4" property="display-seq">4</meta>
 
    <dc:title id="t5">The Great Cookbooks of the World:
        Mon premier guide de cuisson, un Mémoire.
        The New French Cuisine Masters, Volume Two.
        Special Anniversary Edition</dc:title>
    <meta refines="#at5" property="title-type">extended</meta>
    …
</metadata>

[see here for original]

How I'd recommend writing the same thing in JSON...


{
    "metadata": {
        "dc:title": [
            {
                "collection": "The Great Cookbooks of the World"
            },
            [
                "Mon premier guide de cuisson, un Mémoire",
                {
                    "language": "fr"
                }
            ],
            {
                "collection": "The New French Cuisine Master"
            },
            {
                "edition": "Special Anniversary Edition"
            },
            {
                "volume": "Volume 2"
            }
        ]
    }
}

All the same information is contained in this JSON, the order of the title components (implied by actual order), the component types: collection (even though we have two collections), edition, and the plain old title  (which doesn't need any introduction).

I have no idea why the title is in French and the series title is in English but anyway we'll assume the global language is English for the metadata as a whole and the local language is French (see here), and that labelling the language is done for semantic reasons such as automated translation.

What's next?

This title is one of the toughest that the IDPF could come up with, and knowing how straightforward the JSON written here would be to parse in most programming languages, I think this is evidence enough that going forwards EPUB should support JSON as an alternative to XML in the area of metadata at the very least. After all how many times do you really want to read "meta refines"? But I'd really like to hear opinions from others.

Related stuff

Epub-parser

'Epub-parser is a simple way to make working with epub files more programmer- and web-friendly by converting its data structures to JSON and providing some simplified structures for convenient access to that data.' -– https://npmjs.org/package/epub-parser



Comments