Introduction
If you are like me that often produce web based maps often, you will definitely come across situations were you have to convert the most popular geospatial file format (Shapefile) into the most popular web programming language file format - JSON (thta is: GeoJSON in our case since we care more about location elements).
Before I gone to show how you will convert a shapefile to a GeoJSON, let me briefly explain what a JSON file format is and why it is important to us.
What is JSON?
JSON is a short hand for "JavaScript Object Notation". Though JSON has the name JavaScript it can be used in all different languages since most languages have libraries to parse the JSON data.
JSON is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML. It is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language (the way objects are built in JavaScript). It is a much-more compact way of transmitting sets of data across network connections as compared to XML.
JSON values can consist of: objects (collections of name-value pairs) arrays (ordered lists of values) strings (in double quotes) numbers true, false, or null. JSON is language independent.
What are JSON files?
JSON files are the files which contain JSON data. They are saved with a file extension: .json
Conventions used by JSON are known to programmers, which include C, C++, Java, Python, Perl, etc. For instance, in Python programming the awareness of the built-in data structures such as Tuple, List, and Dictionary will help you understand JSON/GeoJSON object.
What does it look like?
A simple json structure may look like this:-
"author": { "name" : "Umar Yusuf", "age" : "23", "gender" : "male", "url" : "http://www.UmarYusuf.com" }
Storing JSON: data as a simple example, information about me might be written in JSON as above.
Storing JSON Data in Arrays: a slightly more complicated example involves storing information about two people. To do this, we enclose multiple objects in square brackets, which signifies an array. For instance, if I needed to include information about myself and my brother, it will look like this below:-
[{ "name" : "Umar Yusuf", "age" : "23", "gender" : "male" "url" : "http://www.UmarYusuf.com" }, { "name" : "Musa Kallamu", "age" : "37", "gender" : "male" "url" : "http://www.mk.com" }, ...]
{ "Umar":{ "name" : "Umar Yusuf", "age" : "23", "gender" : "male" "url" : "http://www.UmarYusuf.com" }, "Musa":{ "name" : "Musa Kallamu", "age" : "37", "gender" : "male" "url" : "http://www.mk.com" }, ... }
Uses of JSON
~ It is used while writing JavaScript based applications that includes browser extensions and websites.
~ JSON format is used for serializing and transmitting structured data over network connection.
~ It is primarily used to transmit data between a server and web applications.
~ Web services and APIs use JSON format to provide public data.
~ It can be used with modern programming languages.