Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


You'll likely have heard about the impending doom changes which will hit EU tech businesses in January 2015. At present, there is no government sponsored API for accessing the current VAT rates for a given country. This very simple Ruby client allows you to access up-to-date VAT rates for any EU country.

This uses the service to obtain its data. Full details can be seen here.

Important notes

This information is provided on an as-is basis. The authors or contributors cannot be held responsible for its accuracy or completeness. You use the data provided by entirely at your own risk.

The API returns the standard & reduced VAT rates for EU countries. In some circumstances, you may need to charge other rates for certain types of product. For a full list, see this document.


gem 'json_vat', '~> 1.0'


You can look up the current rate for any country by providing it's ISO-3166-1-alpha2 code, like so.'GB').rate              #=> 20.0'GB').rate(:reduced)    #=> 5.0

If you want to look up the rate for a different time:

date =, 1, 5)'GB').rate_on(date)             #=> 20.0'GB').rate_on(date, :reduced)   #=> 5.0

If a country doesn't exist, nil will be returned from the call to the country method. If no rate is found, nil will be returned from the rate or rate_on methods.


By default, this will cache the contents of the rates array in a temporary file in /tmp/jsonvat.json. If this file exists, any future reads will be taken from this file.

# Recache the rates from This should be scheduled to run on a semi
# regular basis. If you are setting this up on a cron, please run this at a random
# time to avoid load on our servers at peak times (like midnight).

# To download the current rates manually, you can use this method. This will return
# a string of the data currently available on

# Disable caching and always download the latest data from
JSONVAT.perform_caching = false

If you need to change the cache path, you can do so with this command:

JSONVAT.cache_backend.path = File.join('other', 'path', 'rates.json')

You can also create your own cache backends if you want to store data somewhere other than on your file system. To do this, you need to create a class which responds to the following methods:

  • read - must return the cached data or nil if no data has been cached.
  • write(data) - must write the data to the cache. Return value is not important.
  • invalid? - must return true whenever the cache has been updated and the JSON should be re-parsed

You can find an example in the lib/json_vat/file_cache_backend path which is the default cache used for file system storage.

Once you have created your class, you should set it as the cache backend.

JSONVAT.cache_backend =


A Ruby client library for







No releases published


No packages published

Contributors 4