CSV to JSON Web Service
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
WebContent
src/com/kenlin/tojson
README.md

README.md

2jsonj

CSV to JSON Web Service

The 2json.com web service transforms various data formats (currently CSV) to JSON so web clients can more easily make use of the data.

The web service's REST API is invoked via http://api.2json.com/csv2json/api?url=csvurl.

  • The first row of the source CSV must contain the column titles, like so ...
    Site ID,Intersection,Site Location,Warnings,Citations,Number of Approaches,Sensor Type
  • The remaining rows of the source CSV must contain the row values, like so ...
    PI001,Roosevelt Blvd @ Grant Ave,N/B Roosevelt Blvd Svc @ Grant Ave,2/23/2005,6/23/2005,6,PLP
    

PI002,Roosevelt Blvd @ Grant Ave,N/B Roosevelt Blvd @ Grant Ave,2/23/2005,6/23/2005,6,PLP . . .

{
  "data": {
        "items": [
            {
                "Site ID":"PI001",
                "Intersection":"Roosevelt Blvd @ Grant Ave",
                "Site Location":"N/B Roosevelt Blvd Svc @ Grant Ave",
                "Warnings":"2/23/2005",
                "Citations":"6/23/2005",
                "Number of Approaches":6,
                "Sensor Type":"PLP"
            },
            {
                "Site ID":"PI002",
                "Intersection":"Roosevelt Blvd @ Grant Ave",
                "Site Location":"N/B Roosevelt Blvd @ Grant Ave",
                "Warnings":"2/23/2005",
                "Citations":"6/23/2005",
                "Number of Approaches":6,
                "Sensor Type":"PLP"
            },
            . . .
        ]
    }
}

The table following summarizes the 2json.com technologies used ...

Type Technology
Language Java
Web Server Tomcat
Web Service Framework Spring MVC
JSON Library Jackson
CSV Library Apache Commons CSV
PAAS Amazon Elastic Beanstalk

Example 1 - Philadelphia Red Light Camera Locations

To demonstrate the 2json.com web service, I created a Philadelphia Red Light Camera Locations web page. My web page marks the camera locations obtained from the Open Data Philadelphia Parking Authority CSV file onto Google maps.

Its JavaScript code performs the following steps:

  • Calls the 2json.com web service's REST API asking it to transform the CSV at the given URL to JSON, using
**?url**=https://raw.github.com/CityOfPhiladelphia/ppa-data/master/red-light-cameras/red-light-camera-locations.csv. - Each of the JSON data's "Intersection" strings, like "Roosevelt Blvd @ Grant Ave", are then passed to the Google Maps [Geocoding](https://developers.google.com/maps/documentation/geocoding/) API to obtain their latitude and longitude. Calls are throttled to avoid [OVER_QUERY_LIMIT](https://developers.google.com/maps/documentation/business/articles/usage_limits#limitexceeded). These are then made into Google Maps Markers. - The Google [Maps](https://developers.google.com/maps/documentation/javascript/reference#Map) API is called one more time to drop the Markers onto a map of Philadelphia with some drop animation.

Try me

Example 2 - Craig LaBan's 76 Favorite Restaurants

Alt text
I love good food. Craig LaBan, Philadelphia Inquirer's restaurant critic wrote a book, "Craig LaBan's 76 Favorite Restaurants" which I got as a gift in 2007. I found it difficult to visualize where all these wonderful restaurants were, so I transcribed their locations into my own static Google map.

To demonstrate the 2json.com web service, I copied the information into a CSV file, and then extended the red light camera web page to create a restaurant locations map. Its JavaScript code performs the following interesting steps:

  • The restaurants are rated by "Bells", with 4 being the highest rating. These numbers are placed in custom markers, Alt text following this.
  • The marker background colors were taken from the palest color from D3's category20c.

Try me