WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
how to support another JSON flavour (3 posts)

  1. berteh
    Member
    Posted 1 year ago #

    Hello.

    Thanks for your great plugin, first of all: just works... and code is clean ;)

    What would be the best way to have the plugin serialize the WP data into another flavour of JSON (a.o. leaving most of the internal "technical" informations away, simplifying attachments links, dates, custom categories links and more...)?

    I want to feed my WP posts into a simile exhibit facet browsing view (see ao http://www.simile-widgets.org/exhibit/) , and therefore need a custom JSON looking like below:

    {
        "properties": {
            "taxonomy_sectors": {
                "label": "sector",
                "valueType": "CustomTaxonomyTerm"
            }
        },
        "items": [
            {
                "label": "Some nice post",
                "title": "Some nice post",
                "type": "Post",
                "id": 346,
                "slug": "some-nice-post",
                "url": "http://local/2013/04/29/some-nice-post/",
                "content": "<p>Some nice post</p>\n<p>with long content</p>\n",
                "excerpt": "<p>Some nice post</p>\n",
                "date": "2013-04-29",
                "thumbnail": "http://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Portrait_of_George_Washington.jpeg/100px-Portrait_of_George_Washington.jpeg",
                "tags": [
                    "president",
                    "nice",
                    "USA"
                ],
                "categories": [
                    "Person",
                    "Politics"
                ],
                "taxonomy_sectors": [
                    "Construction",
                    "Tourism"
                ],
                "author": "Coco"
            },
            {
                "label": "Construction",
                "description": "Building & Real-Estate",
                "slug": "construction",
                "id": 56,
                "url": "http://local/?sectors=construction",
                "type": "CustomTaxonomyTerm"
            },
            {
                "label": "Tourism",
                "description": "Hotels, Caf├ęs, Festivals and more",
                "slug": "tourism",
                "id": 72,
                "url": "http://local/?sectors=tourism",
                "type": "CustomTaxonomyTerm"
            }
        ]
    }

    Official sample JSON file at http://simile.mit.edu/wiki/Exhibit/Template/JSON_Data_File - official documentation at http://simile.mit.edu/wiki/Exhibit/Understanding_Exhibit_Database

    Any pointer / suggestion is welcome.
    Berteh.

    http://wordpress.org/plugins/json-api/

  2. berteh
    Member
    Posted 1 year ago #

    Possible ways I see this is to
    1) implement my own model for posts, or
    2) to hack the generated associative array by putting a filter on 'json_api_encode' that would convert it to my needs or
    3) setting a JS callback that would to the same on the JSON.

    What is the best way? (could be something completely different too, let me know!)

  3. Daedalon
    Member
    Posted 11 months ago #

    Looks like this might be doable with just a custom controller. Make a copy of the core controller, rename the class and other relevant parts and modify the formatting of the JSON to be the desired flavour.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic