How to Query Google’s Currency Converter using JSON API?


The world is big and there are various currencies available for various countries. Some time we need to convert an amount from one currency to another, some time we want to see the current market price of one currency to other. Maximum time we need to check the USA market value in terms of US dollar.

 

To do this, we generally search in Google to get the current market value of currency. Now think a scenario when you want to integrate it in your application. In this post I will discuss about the converter API and how to retrieve the result using JSON.

 

Apart from Google, there are many other websites too which provide online currency conversion. Here we will discuss about the Google’s Currency Conversion Calculator API using JSON object. Google’s currency converter uses a secret open API for all types of foreign currency conversion.

 

How to use Google’s Currency Converter using JSON API?

If you want to use this JSON API for doing the currency conversion, you can build your query string and pass to the http://www.google.com/ig/calculator URL for processing.

 

The correct form of the URL will be: http://www.google.com/ig/calculator?hl=en&q=[VALUE][FROM_CODE]=?[TO_CODE]

 

Notice the above URL. [VALUE] represents the amount that you want to pass to the converter, [FROM_CODE] and [TO_CODE] represents the currency code of respective currencies.

 

For example, if you want to convert currency from 1 USD to INR, you have to construct the following URL:

http://www.google.com/ig/calculator?hl=en&q=1USD=?INR

 

The above link will return you the below JSON object, which you can extract to get the converted value:

{lhs: "1 U.S. dollar",rhs: "55.8284949 Indian rupees",error: "",icc: true}

 

I hope, this small post will be useful to you in near future. So don’t forget to bookmark it. If you came to this post by searching online, use the logic mentioned above to construct your URL and retrieve the converted currency value from the JSON object returned by the Google API. All the best and Happy Coding!!!


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments


 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top