ram-nadella / airport-codes

Airport codes (IATA) and their corresponding information. Also available as a web service.
airport-codes.herokuapp.com
29 stars 18 forks source link

Bad format JSON #1

Open smidaharoun opened 8 years ago

smidaharoun commented 8 years ago

It should be JSONArray instead of JSONObject. It making it harder to deal with

ram-nadella commented 8 years ago

@smidaharoun the JSON is structured that way to allow the case of a single code lookup in the dictionary rather than having to iterate over the entire list.

Which language are you working in? Is there a way to get the values from the JSONObject? Or may be get the keys as a list and then iterate over the keys and get the values that way?

If you can't find a solution, applying the patch below will change the code to generate a JSON with an array of airport data objects. Run ruby reformat.rb at the root of the repo to get the generated airports.json file.

diff --git a/reformat.rb b/reformat.rb
index 708ada9..f5911a9 100644
--- a/reformat.rb
+++ b/reformat.rb
@@ -1,10 +1,10 @@
 require "csv"
 require "json"

-airport_data = {}
+airport_data = []

 CSV.foreach("airports.dat") do |row|
-  airport_data[row[4]] = {
+  airport_data << {
     :name => row[1],
     :city => row[2],
     :country => row[3],
ptrkstr commented 2 years ago

This should be closed as it's not an issue. It is valid json and is in a format that improves look up speed.