> nohup _

Using JSON in Google Flights

Google Flights API uses JSON Arrays to send and receive data to and fro its RPC server www.google.com/flights/rpc.

A flight search via a URL like www.google.com/flights/#search;f=SJC;t=EWR,JFK,LGA;d=2012-04-05;r=2012-04-12 causes search results to be returned in 5 parts.

In each HTTP POST request to the RPC server, the custom HTTP Headers X-GWT-Permutation and X-GWT-Module-Base are required to be sent, otherwise there will be no response.

X-GWT-Permutation is the 32 character MD5 hash that is used to uniquely name files in the GWT build. This header is sent with each request to the RPC server to prevent cross-site scripting.

Part 1: Search parameter fs:

HTTP Request Header Value
(Request-Line) POST /flights/rpc HTTP/1.1
Host www.google.com
Content-Type application/json; charset=utf-8
X-GWT-Permutation 0BB89375061712D90759336B50687E78
X-GWT-Module-Base http://www.google.com/flights/static/
Referer http://www.google.com/flights/
Content-Length 275
Cookie PREF=ID=2dc218fc830df28d:U=29aaf343dd519bca:FF=0:TM=1307225398:LM=1308065727:GM=1:S=RWC3dYzVvVSpkrlz; NID=52=VTp1QILW1ntPlrkLx7yLUtOYhchNk35G4Lk35KBd7A3lCznVV5glz7lwDoDP2RkjtTJVNZSomv3iffPqiJz4oXfpoph3ljb2eInGOe-FwosvrmSXPpnLkEWxMHIbuaid; S=travel-flights=YFCjkd9M9h3Z_uEqBmgynA
Pragma no-cache
Cache-Control no-cache
 

The flight search parameters are sent as JSON Arrays inside HTTP POST data:

[,[[,"fs","[,[,[\"SJC\"]\n,\"2012-04-05\",[\"EWR\",\"JFK\",\"LGA\"]\n,\"2012-04-12\"]\n]\n"]
]
,[,[[,"b_ca","54"]
,[,"f_ut","search;f=SJC;t=EWR,JFK,LGA;d=2012-04-05;r=2012-04-12"]
,[,"b_lr","11:36"]
,[,"b_lr","1:1528"]
,[,"b_lr","2:1827"]
,[,"b_qu","3"]
,[,"b_qc","1"]
]
]
]

The search results are received as a very large JSON Array of approximate size 150 KB. After a little cleaning up, the array reads as follows (courtesy the pretty JSON parser at json.parser.online.fr:

[JSON Parser - Request flight search info]
[
    [
        [
            "fs",
            [
                [
                    [
                        "MIC",
                        "Crystal",
                        "Minneapolis",
                        "MSP",
                        "United States",
                        45.06194444444444,
                        -93.35388888888889,
                        "MN"
                    ],
                    [
                        //36 more airports with information in this format
                        3 letter airport code,
                        airport name,
                        city in which airport is located,
                        3 letter city code,
                        country name,
                        latitude of airport location,
                        longitude of airport location,
                        state in which airport is located
                    ],
                ],
                [
                    [
                        "UA",
                        "United Airlines",
                        "STAR_ALLIANCE",
                        "United",
                        "http://www.united.com/"
                    ],
                    [
                        //6 more airlines that serve these airports
                        2 letter airline code,
                        airline name",
                        alliance code,
                        airline short name,
                        airline website"
                    ],
                ],
                [
                    [
                        "LAX",
                        "Los Angeles",
                        33.94222222222222,
                        -118.40722222222223,
                        [
                            "LAX",
                            "VNY",
                            "WHP",
                            "QLO",
                            "CCD",
                            "JWC"
                        ],
                        [
                            "LAX"
                        ],
                        "United States",
                        "CA"
                    ],
                    [
                        "NYC",
                        "New York",
                        40.70861111111111,
                        -73.72527777777778,
                        [
                            "QNY",
                            "EWR",
                            "JFK",
                            "LGA",
                            "FLU",
                            "XNY"
                        ],
                        [
                            "EWR",
                            "JFK",
                            "LGA"
                        ],
                        "United States",
                        "NY"
                    ],
                    [
                        //nearby airports for cities
                        3 letter city code,
                        city name,
                        latitude of city location,
                        longitude of city location,
                        [
                            //list of nearby airports for domestic airlines,
                        ],
                        [
                            //list of nearby airports for international airlines,
                        ],
                        country name,
                        state in which airport is located
                    ],
                    ]
                ],
                [
                    [
                        [
                            0,
                            [
                                [
                                    [
                                        "SJC",
                                        "2012-04-05T09:40:00-07:00",
                                        "LAX",
                                        "2012-04-05T11:00:00-07:00",
                                        "AS",
                                        "2403",
                                        "",
                                        "Horizon Air DBA Alaska Horizon"
                                    ],
                                    [
                                        "LAX",
                                        "2012-04-05T13:30:00-07:00",
                                        "JFK",
                                        "2012-04-05T22:05:00-04:00",
                                        "DL",
                                        "1934"
                                    ]
                                ],
                                2000,
                                2000
                            ]
                        ],
                        [
                            1,
                            [
                                [
                                    [
                                        "JFK",
                                        "2012-04-12T07:00:00-04:00",
                                        "SLC",
                                        "2012-04-12T10:13:00-06:00",
                                        "DL",
                                        "1415"
                                    ],
                                    [
                                        "SLC",
                                        "2012-04-12T11:30:00-06:00",
                                        "SJC",
                                        "2012-04-12T12:35:00-07:00",
                                        "DL",
                                        "1741"
                                    ]
                                ],
                                2300,
                                3200
                            ]
                        ],
                        [
                            //index of the array of all possible flights 
                            [
                                [
                                    [
                                        3 letter departure airport code,
                                        departure date timestamp with timezone,
                                        3 letter stopover airport code,
                                        arrival date timestamp with timezone,
                                        2 letter airline code,
                                        flight number
                                    ],
                                    [
                                        3 letter stopover airport code,
                                        departure date timestamp with timezone,
                                        3 letter arrival airport code,
                                        arrival date timestamp with timezone,
                                        2 letter airline code,
                                        flight number,
                                        (optional) currently blank,
                                        (optional) airline sharing code
                                    ]
                                ],
                                (don't know yet),
                                (don't know yet)
                            ]
                        ],
                            ]
                        ]
                    ],
                    [
                        [
                            [
                                33,
                                46
                            ],
                            51100,
                            0,
                            [
                                [
                                    [
                                        [
                                            "AA",
                                            "582"
                                        ],
                                        [
                                            "AA",
                                            "744"
                                        ]
                                    ]
                                ],
                                [
                                    [
                                        [
                                            "AA",
                                            "305"
                                        ],
                                        [
                                            "AA",
                                            "1041"
                                        ]
                                    ]
                                ]
                            ],
                            1
                        ],
                        [
                            [
                                array index of outbound flight,
                                array index of inbound flight
                            ],
                            ticket price (in cents not dollars),
                            (don't know yet - possible boolean value),
                            [
                                [
                                    [
                                        [
                                            2 letter airline code of first leg of outbound flight,
                                            flight number of first leg of outbound flight
                                        ],
                                        [
                                            2 letter airline code of second leg of outbound flight,
                                            flight number of second leg of outbound flight
                                        ]
                                    ]
                                ],
                                [
                                    [
                                        [
                                            2 letter airline code of first leg of inbound flight,
                                            flight number of first leg of inbound flight
                                        ],
                                        [
                                            2 letter airline code of second leg of inbound flight,
                                            flight number of second leg of inbound flight
                                        ]
                                    ]
                                ]
                            ],
                            (don't know yet - possible boolean value)
                        ]
                    ]
                ],
                (don't know yet)
            ]
        ]
    ],
    [
    ]
]

Part 2: Search parameter ld:

HTTP Request Header Value
(Request-Line) POST /flights/rpc HTTP/1.1
Host www.google.com
Content-Type application/json; charset=utf-8
X-GWT-Permutation 0BB89375061712D90759336B50687E78
X-GWT-Module-Base http://www.google.com/flights/static/
Referer http://www.google.com/flights/
Content-Length 87
Cookie PREF=ID=2dc218fc830df28d:U=29aaf343dd519bca:FF=0:TM=1307225398:LM=1308065727:GM=1:S=RWC3dYzVvVSpkrlz; NID=52=VTp1QILW1ntPlrkLx7yLUtOYhchNk35G4Lk35KBd7A3lCznVV5glz7lwDoDP2RkjtTJVNZSomv3iffPqiJz4oXfpoph3ljb2eInGOe-FwosvrmSXPpnLkEWxMHIbuaid; S=travel-flights=YFCjkd9M9h3Z_uEqBmgynA
Pragma no-cache
Cache-Control no-cache
 

The next HTTP POST request is for all airports close to the destination airport:

[,[[,"ld","[,[\"EWR\",\"JFK\",\"LGA\"]\n]\n"]
]
,[,[[,"b_qu","2"]
,[,"b_qc","2"]
]
]
]
[Google Flight Search - Request nearby airports]
 

Cleaned up and parsed out, here is the response:

[JSON Parser - Request nearby airports]
[
    [
        [
            "ld",
            [
                [
                    [
                        "EWR",
                        "Newark Liberty International",
                        "New York",
                        "NYC",
                        "United States",
                        40.69583333333333,
                        -74.17166666666667,
                        "NY"
                    ],
                    [
                        "JFK",
                        "John F. Kennedy International",
                        "New York",
                        "NYC",
                        "United States",
                        40.63861111111111,
                        -73.77694444444444,
                        "NY"
                    ],
                    [
                        "LGA",
                        "La Guardia",
                        "New York",
                        "NYC",
                        "United States",
                        40.779444444444444,
                        -73.87583333333333,
                        "NY"
                    ]
                ],
                "",
                [
                    [
                        "NYC",
                        "New York",
                        40.70861111111111,
                        -73.72527777777778,
                        [
                            "QNY",
                            "EWR",
                            "JFK",
                            "LGA",
                            "FLU",
                            "XNY"
                        ],
                        [
                            "EWR",
                            "JFK",
                            "LGA"
                        ],
                        "United States",
                        "NY"
                    ]
                ]
            ]
        ]
    ],
    [
    ]
]

Part 3: Search parameter dl:

HTTP Request Header Value
(Request-Line) POST /flights/rpc HTTP/1.1
Host www.google.com
Content-Type application/json; charset=utf-8
X-GWT-Permutation 0BB89375061712D90759336B50687E78
X-GWT-Module-Base http://www.google.com/flights/static/
Referer http://www.google.com/flights/
Content-Length 134
Cookie PREF=ID=2dc218fc830df28d:U=29aaf343dd519bca:FF=0:TM=1307225398:LM=1308065727:GM=1:S=RWC3dYzVvVSpkrlz; NID=52=VTp1QILW1ntPlrkLx7yLUtOYhchNk35G4Lk35KBd7A3lCznVV5glz7lwDoDP2RkjtTJVNZSomv3iffPqiJz4oXfpoph3ljb2eInGOe-FwosvrmSXPpnLkEWxMHIbuaid; S=travel-flights=YFCjkd9M9h3Z_uEqBmgynA
Pragma no-cache
Cache-Control no-cache
 

The next HTTP POST request is for the best price and the flight duration in minutes:

[,[[,"dl","[,[,[\"SJC\"]\n,\"2012-04-05\",[\"EWR\",\"JFK\",\"LGA\"]\n,\"2012-04-12\"]\n]\n"]
]
,[,[[,"b_qu","1"]
,[,"b_qc","3"]
]
]
]
[Google Flight Search - Request best price and flight duration]
 

Cleaned up and parsed out, here is the response:

[JSON Parser - Request best price and flight duration]
[
    [
        [
            "dl",
            [
                [
                    48500,
                    609
                ]
            ]
        ]
    ],
    [
    ]
]

Part 4: Search parameter tb:

HTTP Request Header Value
(Request-Line) POST /flights/rpc HTTP/1.1
Host www.google.com
Content-Type application/json; charset=utf-8
X-GWT-Permutation 0BB89375061712D90759336B50687E78
X-GWT-Module-Base http://www.google.com/flights/static/
Referer http://www.google.com/flights/
Content-Length 134
Cookie PREF=ID=2dc218fc830df28d:U=29aaf343dd519bca:FF=0:TM=1307225398:LM=1308065727:GM=1:S=RWC3dYzVvVSpkrlz; NID=52=VTp1QILW1ntPlrkLx7yLUtOYhchNk35G4Lk35KBd7A3lCznVV5glz7lwDoDP2RkjtTJVNZSomv3iffPqiJz4oXfpoph3ljb2eInGOe-FwosvrmSXPpnLkEWxMHIbuaid; S=travel-flights=YFCjkd9M9h3Z_uEqBmgynA
Pragma no-cache
Cache-Control no-cache
 

The next HTTP POST request is for the latitude and longitude of all airports in order to plot them on the map:

[,[[,"tb","[,[,[\"SJC\"]\n,\"2011-10-24\",[\"EWR\",\"JFK\",\"LGA\"]\n,\"2011-10-31\"]\n]\n"]
]
,[,[[,"b_qu","0"]
,[,"b_qc","4"]
]
]
]
[Google Flight Search - Request airport lat-long info]
 

Cleaned up and parsed out, here is the response:

[JSON Parser - Request airport lat-long info]
[
    "tb",
    [
        "CO",
        "Continental Airlines",
        "STAR_ALLIANCE",
        "Continental",
        "http://www.continental.com/"
    ], //...more airlines...
    [
        [
            "ATL",
            "Hartsfield-Jackson Atlanta International",
            "Atlanta",
            "ATL",
            "United States",
            33.64083333333333,
            -84.42722222222223,
            "GA"
        ], //...more airports...
]

It appears that the same airline information that was fetched in Part 2 is being fetched again here in Part 4; this probably represents an opportunity for code optimization.

Part 5: Search parameter ss:

HTTP Request Header Value
(Request-Line) POST /flights/rpc HTTP/1.1
Host www.google.com
Content-Type application/json; charset=utf-8
X-GWT-Permutation 0BB89375061712D90759336B50687E78
X-GWT-Module-Base http://www.google.com/flights/static/
Referer http://www.google.com/flights/
Content-Length 317
Cookie PREF=ID=2dc218fc830df28d:U=29aaf343dd519bca:FF=0:TM=1307225398:LM=1308065727:GM=1:S=RWC3dYzVvVSpkrlz; NID=52=VTp1QILW1ntPlrkLx7yLUtOYhchNk35G4Lk35KBd7A3lCznVV5glz7lwDoDP2RkjtTJVNZSomv3iffPqiJz4oXfpoph3ljb2eInGOe-FwosvrmSXPpnLkEWxMHIbuaid; S=travel-flights=YFCjkd9M9h3Z_uEqBmgynA
Pragma no-cache
Cache-Control no-cache
 

The next HTTP POST request is for URLs that would allow the user to search other sources using the same flight parameters:

[,[[,"ss","[,\"4B0037E52E578.A2AD345.2B29\",1,[\"SJC\"]\n,[\"EWR\",\"JFK\",\"LGA\"]\n,\"2012-04-05\",\"2012-04-12\",6]\n"]
]
,[,[[,"b_lr","13:1304"]
,[,"b_ac","dl"]
,[,"b_lr","11:42"]
,[,"b_lr","13:361"]
,[,"b_lr","5:80"]
,[,"b_lr","6:279"]
,[,"b_lr","4:4167"]
,[,"b_lr","3:2418"]
,[,"b_qu","0"]
,[,"b_qc","1"]
]
]
]
[Google Flight Search - Request other source URLs]
 

Cleaned up and parsed out, here is the response:

[JSON Parser - Request other source URLs]

The URLs below, when clicked, are decoded by the GWT application into URLs specific to the flight search provider. For example, the URL for Kayak resolves to www.kayak.com/r/EECCnU86F.

[
    "ss",
    [
        [
            [
                "priceline",
                "Priceline",
                "http://www.google.com/travel/clk/f?su\\u003dC...QvMDUvMjAxMg"
            ],
            [
                "expedia",
                "Expedia",
                "http://www.google.com/travel/clk/f?su\\u003dC...QvMDUvMjAxMg"
            ],
            [
                "orbitz",
                "Orbitz",
                "http://www.google.com/travel/clk/f?su\\u003dC...MDEyLTA0LTA1"
            ],
            [
                "travelocity",
                "Travelocity",
                "http://www.google.com/travel/clk/f?su\\u003dC...0LzA1LzIwMTI"
            ],
            [
                "cheapoair",
                "Cheapoair",
                "http://www.google.com/travel/clk/f?su\\u003dC...QvMDUvMjAxMg"
            ],
            [
                "kayak",
                "Kayak",
                "http://www.google.com/travel/clk/f?su\\u003dC...QvMDUvMjAxMg"
            ]
        ]
    ]
]

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.