views:

240

answers:

3

I have a nightly executable that will run on a windows or linux server that will be downloading information from various web sources and one of those sources contains a JSON response. This executable will download the information and connect to a SQL server database to update the appropriate records.

I come from a C#, windows programming background so my natural inclination is to use the JSON.net libraries or create custom code to parse the JSON text using C#. But I'd really rather use the appropriate scripting language to take advantage of the eval() statement to process the JSON.

Does anyone have a suggestion for which scripting language and development environment that would be best suited for this kind of server process? It doesn't matter to me if it runs on the linux or windows server, I just want to use the best tool available.

A: 

The eval() technique only works within JavaScript, as JSON is valid JavaScript syntax. You might be able to use something like Rhino (Java), but otherwise every language you choose will require using a JSON library. Since you are most familiar with C# and .NET, it seems like the most logical choice if the target machine already has it available.

James M.
A: 

JSONsharp (.Net 2.0+) or JSON.net (.Net 3.5) are your friends here, as are others on JSON.org.

But beware the eval() statement in JavaScript - it executes the JSON, so if someone has put javascript in there, you may find yourself running code. Instead you would want to use something like JSON.parse.

lavinio
A: 

Any scripting environment should be fine, and nearly all have decent JSON parsers built in.

Here's a Python example (requires Python 2.6 and up for the built-in json module, otherwise download simplejson):

import urllib2, json
response = urllib2.urlopen("http://example.net/url/for/json").read()
data = json.loads(response) # returns a native Python type, e.g. a dictionary

# your code here
process_and_update_db(data)

If you want to use .NET (may be easier to access your DB, for example), and want a good scripting language like Python, try IronPython. You can use download and use simplejson instead of json.

orip