I'm trying to implement a rest api. It works with a normal request but I'd like to return a jsonp when called with a callback function.

This function returns a json array of all restaurants in the database.

Json getRestaurants()
    {
        Json restaurantList = Json.emptyObject();
        restaurantList["restaurants"] = Json.emptyArray();
        foreach (doc; collection.find())
        {
            restaurantList["restaurants"] ~= [doc.toJson()];
        }
        return restaurantList;
    }

How could I implement it so that with the url /restaurants?callback=parse it returns parse({"restaurants":[{"_id":"...}]})?

Thank you for taking the time.