Issues

Issue #30 on hold

JSON format and nojsoncallback param support

Gonzalo Saavedra
created an issue

It' seems that the nojsoncallback parameter it's not currently supported:

If you just want the raw JSON, with no function wrapper, add the parameter nojsoncallback with a value of 1 to your request.

Supporting this for json format requests would allow, for example, to directly feed the response to json.loads which seems to be a very common use case.

Comments (6)

  1. Gonzalo Saavedra reporter

    Hey Sybren,

    I should have set the "Kind" field to "enhancement" since this is not a bug.

    When setting format='json' on an API query, photos_search() for example, you get a string that's not valid json, it's valid javascript, since it's wrapped with a callback by default:

    'jsonFlickrApi({"photos":{"page":1, "pages":6687, "perpage":100, "total":"668645", ... })'
    

    Flickr API allows you to change the callback name with the parameter jsoncallback or not using a callback at all with nojsoncallback parameter.

    Usually when coding in python you want to convert the json string to a dict to process it, if you want to feed it to json.loads you need to convert it to a valid json string, by getting rid of the jsonFlickrApi() string yourself.

    Since this seems like a common usage and since flickr supports returning a response with no callback (valid json) it would be great to have support for this.

  2. Sybren Stüvel repo owner

    Please, show me a program that uses the Python FlickrAPI code, which demonstrates your problem. nojsoncallback=1 is actually a default parameter, so you shouldn't even need it to get parseable results.

    I've just added an extra "format" called "parsed-json", which automatically UTF8-decodes the response and parses it as JSON, returning it as a dictionary.

    Check http://stuvel.eu/files/flickrapi-beta-docs/2-calling.html#response-format-json for more info.

  3. Log in to comment