So my latest endeavor is to learn JSON.  I mentioned in an earlier post how I do research all the time.  Well, I stumbled across a subject called SOA (Service Oriented Architecture) and I started to read articles on the Internet and decided that this is a major subject that I wanted to know about.  So I bought a book (and of course, I’m still waiting for the book to arrive).  In the mean time, I discovered this data exchange format called JSON.  One of the first projects I tested reads data from a currency service.  The code and instructions are located here:

Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy!

It’s from codeproject, and it worked the first time.  One step that was different involved the currency exchange service.  They changed their requirements and they require an id to download their data.  They also have a different link, but it’s easy to get this information by going to their site:

Open Exchange Org

Click the “Get Instant Access” button and look for the little “free” link at the bottom. You can enter your email information and get an account for development purposes for free.  This will then lead you to a webpage that gives you an “App ID” and instructions including the actual link you need to call to receive data in JSON format.

Back to JSON

So I’m looking at how JSON is able to get data from a remote website and use it within my own website.  Then I discovered a weather service that is free and provides a JSON API.  The reason this interested me is that my company does site management for roofing.  What site managers do is they watch the roofing contractors install the roof and they mark of the information on a daily quality report.  The quality report includes information about the local weather.  The purpose of recording all this information is to resolve disputes in the future if a roof system fails.  Here’s a list of weather services that provide JSON data:

Weather services using JSON

and here’s the free one that I’m currently looking at:

Free Weather API for developers

What’s the purpose?

The weather information that can be read from this website can be transferred to my website by clicking a button.  My intention is to be able to read the weather for the current location at a designated date (site managers can create a quality report after they have performed the site inspection, so they might want to record yesterday’s data, for instance), then pre-populate the weather fields in the quality report.  This relieves the site manager from going to a weather service and looking up what the official weather was for that date (site managers don’t carry weather measuring equipment like thermometers and anemometers).

My real purpose in doing these exercises is to be able to communicate between two processes on different computers.  I have developed “Service” type applications that sit on a dedicated machine and poll a database queue waiting for some data to crunch.  The purpose of doing this is to be able to process lengthy data from a website without requiring the web consumer to stay logged in while the data is being processed.  Web users can process huge numbers of data points and come back and check the progress later.  Meanwhile the data is being processed by a machine in the computer room that is running a service type program.  One major inefficiency of polling in general, is that it is wasting time and resource constantly reading the database to see if there is something in the queue.  Over 99% of the time, there is nothing in the queue to process, so this constant querying (usually every 2 seconds) is consuming resources.  Also, the poll time determines how fast the process will respond to a request.  In order to make this all more efficient, it would be better to queue the items needed to be processed, then send a JSON message to the service to indicate that it needs to process a bunch of data.  That way the remote service application doesn’t have to constantly poll the database.

So what is JSON anyway?

JSON is a lot like XML.  It’s a data transmission format.  It’s very clever in that it’s more compact than XML and it can be directly translated into an object in C# or JavaScript (and many other languages).  It’s also language independent.  For example, a service running Python could provide a JSON encoded data string that can be consumed by a C# program.  This means that a mainframe computer system could communicate with an IIS server without requiring a programmer with knowledge of both languages used.  Two programmers could agree on the JSON format between the two machines and they could each create an interface to communicate between machines.

My motto: Never stop learning.


Leave a Reply