Fusion Tables to JSON

Fusion Tables to JSON is a simple interface that accepts Google Fusion Tables API queries and passes the query to the Fusion Tables API and translates the response into JSON instead of CSV.

For example take a look at the following query: SELECT * FROM 1j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ

JSON Structure

There is a little extra structure to the JSON over the CSV result from Fusion Tables to make it a little easier to page results and parse. A sample of the structure is below.

{
    "count" : 100,
    "start" : 0,
    "limit" : 100,
    "data" : [
        { /* ... Fusion Table data ... */ },
        /* ... */
    ]
}

Query Parameters

The query service for FT2JSON supports some extra parameters to allow paging data and authentication to Google services. You can send all requests as GET or POST regardless of the type of Fusion Tables API query you are doing.

Parameter Type Default Description
start integer 0 The index of the result set to start at. Only supported when doing a SELECT query.
limit integer 100 Limits the total number of results returned. Only supported when doing a SELECT query.
access_token string   OAuth2 access token to use to authenitcate to Fusion Tables. This will allow for doing modifiying queries, working with protected data, etc. More details below.
jsonp string   Name of a callback function defined in the target page's Javascript. This allows direct embedding of result data with script tags. More details below.

Javascript API

There is also simple Javascript API that gives you an easy way to access Fusion Tables data. This way you can work with Fusion Tables entirely on the client side.

To access the Javascript API follow the sample code below.

<script src="http://ft2json.appspot.com/api/ft2json.js" type="text/javascript"></script>
<script type="text/javascript">
ft2json.query(
    'SELECT * FROM 1j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ', /* Fusion Tables query. */
    function(result) {
        /* Callback function. */
        alert(typeof result);
    },
    {
        /* Optional parameters. */
        start : 25,
        limit : 50
    }
);
</script>

Live samples can be found here.

Authentication

You can send authenticated requests to Fusion Tables through this service using OAuth2 bearer tokens. However it is up to your application to work with Google's OAuth2 client API to generate the tokens. Once you have your OAuth2 bearer token generated you can add it to your requests with the access_token parameter through both the query service or the Javascript API.

http://ft2json.appspot.com/q?sql=SELECT * FROM 1j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ&access_token=...

or

ft2json.query(
    'SELECT * FROM 1j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ',
    function(result) {
        alert(typeof result);
    },
    {
        access_token : '...'
    }
);

JSONP Support

If you are just looking for a simple way to grab some data out of Fusion Tables and use it on a web page, this interface will also support JSONP. JSONP gives you an easy way to include JSON data into your scripts by embedding a single script tag.

To use JSONP with FT2JSON, simply add a parameter to your query called jsonp with the value of the name of the Javascript callback function you want the result data passed to.

For example:

<script src="http://ft2json.appspot.com/q?sql=SELECT%20*%20FROM%201j1kKW9s9CrtZ6_o6MdC-xb0YNWb73rQQYENmzQ&jsonp=myCallback" type="text/javascript"></script>

This will return Javascript code like:

myCallback({"data" : [ /* ... RESULT JSON ... */ ], "success" : true /* ... */ });

This is just an extra way to grab some data and work with it without using the Javascript API described above.


Created by Jordon Mears