Evaluating JSON from popular auto-suggests

I was evaluating the various ways in which the big guys implement auto suggest. These are my observations.(Search string used was “ab”) Questions towards the end.

Yahoo tries something like this, where the response was a JSONP. Response is readable and serves the purpose.

Yahoo’s response

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>yasearch({"q":"ab ","gprid":"Y435dN7TRFqnYqQhnBueJA","f":["k","m"],"r":[["ab de villiers",0],["ab exercises",0],["ab king pro",0],
["ab infi-net internet banking",0],["ab mujhe raat din",0],["ab workouts",0],["ab mp3",0],["ab meri bari",0],["ab ke baras",0],["ab meri baari",0]]})
</code>
<code>yasearch({"q":"ab ","gprid":"Y435dN7TRFqnYqQhnBueJA","f":["k","m"],"r":[["ab de villiers",0],["ab exercises",0],["ab king pro",0], ["ab infi-net internet banking",0],["ab mujhe raat din",0],["ab workouts",0],["ab mp3",0],["ab meri bari",0],["ab ke baras",0],["ab meri baari",0]]}) </code>
yasearch({"q":"ab ","gprid":"Y435dN7TRFqnYqQhnBueJA","f":["k","m"],"r":[["ab de villiers",0],["ab exercises",0],["ab king pro",0],
["ab infi-net internet banking",0],["ab mujhe raat din",0],["ab workouts",0],["ab mp3",0],["ab meri bari",0],["ab ke baras",0],["ab meri baari",0]]})

Bing had a similar approach. Returns an “if” block, sa_inst.apiCB() seems to be a function which would process the JSON. Again response is readable and legit.

Bing’s response

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>if(typeof sa_inst.apiCB == 'function') sa_inst.apiCB({"AS":{"Query":"ab","FullResults":1,"Results":[{"Type":"AS","Suggests": [{"Txt":"ab<strong>p</strong> <strong>news</strong>","Type":"AS","Sk":""},
{"Txt":"ab<strong>bottapp</strong>.ab<strong>bott</strong>.<strong>in</strong>","Type":"AS","Sk":"AS1"},{"Txt":"ab<strong>t</strong> <strong>travels</strong>","Type":"AS","Sk":"AS2"},{"Txt":"ab<strong>p</strong> <strong>ananda</strong>","Type":"AS","Sk":"AS3"},
{"Txt":"ab<strong>hibus</strong>","Type":"AS","Sk":"AS4"},{"Txt":"ab<strong>p</strong> <strong>maza</strong>","Type":"AS","Sk":"AS5"}, {"Txt":"ab<strong>b</strong>","Type":"AS","Sk":"AS6"},
{"Txt":"ab<strong>outgoogle</strong>","Type":"AS","Sk":"AS7"}]}]}} /* pageview_candidate */);
</code>
<code>if(typeof sa_inst.apiCB == 'function') sa_inst.apiCB({"AS":{"Query":"ab","FullResults":1,"Results":[{"Type":"AS","Suggests": [{"Txt":"ab<strong>p</strong> <strong>news</strong>","Type":"AS","Sk":""}, {"Txt":"ab<strong>bottapp</strong>.ab<strong>bott</strong>.<strong>in</strong>","Type":"AS","Sk":"AS1"},{"Txt":"ab<strong>t</strong> <strong>travels</strong>","Type":"AS","Sk":"AS2"},{"Txt":"ab<strong>p</strong> <strong>ananda</strong>","Type":"AS","Sk":"AS3"}, {"Txt":"ab<strong>hibus</strong>","Type":"AS","Sk":"AS4"},{"Txt":"ab<strong>p</strong> <strong>maza</strong>","Type":"AS","Sk":"AS5"}, {"Txt":"ab<strong>b</strong>","Type":"AS","Sk":"AS6"}, {"Txt":"ab<strong>outgoogle</strong>","Type":"AS","Sk":"AS7"}]}]}} /* pageview_candidate */); </code>
if(typeof sa_inst.apiCB == 'function') sa_inst.apiCB({"AS":{"Query":"ab","FullResults":1,"Results":[{"Type":"AS","Suggests": [{"Txt":"ab<strong>p</strong> <strong>news</strong>","Type":"AS","Sk":""}, 
{"Txt":"ab<strong>bottapp</strong>.ab<strong>bott</strong>.<strong>in</strong>","Type":"AS","Sk":"AS1"},{"Txt":"ab<strong>t</strong> <strong>travels</strong>","Type":"AS","Sk":"AS2"},{"Txt":"ab<strong>p</strong> <strong>ananda</strong>","Type":"AS","Sk":"AS3"},
{"Txt":"ab<strong>hibus</strong>","Type":"AS","Sk":"AS4"},{"Txt":"ab<strong>p</strong> <strong>maza</strong>","Type":"AS","Sk":"AS5"},  {"Txt":"ab<strong>b</strong>","Type":"AS","Sk":"AS6"},
{"Txt":"ab<strong>outgoogle</strong>","Type":"AS","Sk":"AS7"}]}]}} /* pageview_candidate */);

Now comes Google. Response is sent as 2 JSON objects(separated by /””/). Most of it is unreadable.

Google’s response

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtruex26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[x22abx22,
[[x22ab\u003Cb\u003Ec\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ec news\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Eercrombie\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ecya\u003C\/b\u003Ex22,0,[]]],
{x22jx22:x22dx22,x22qx22:x22t8z6h8KhWvbkEX6xablxgYxDUq4x22,x22tx22:
{x22bpcx22:false,x22tlwx22:false}}]"}
/*""*/
{e:"XteVUYKqDoKHrAfdz4D4Aw",c:-1,u:"https://www.google.com/searchdata?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtrue
x26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",
p:true,d:"{x22snpx22:1}"}
/*""*/
</code>
<code>{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtruex26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[x22abx22, [[x22ab\u003Cb\u003Ec\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ec news\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Eercrombie\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ecya\u003C\/b\u003Ex22,0,[]]], {x22jx22:x22dx22,x22qx22:x22t8z6h8KhWvbkEX6xablxgYxDUq4x22,x22tx22: {x22bpcx22:false,x22tlwx22:false}}]"} /*""*/ {e:"XteVUYKqDoKHrAfdz4D4Aw",c:-1,u:"https://www.google.com/searchdata?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtrue x26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1", p:true,d:"{x22snpx22:1}"} /*""*/ </code>
{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtruex26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[x22abx22,     
[[x22ab\u003Cb\u003Ec\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ec news\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Eercrombie\u003C\/b\u003Ex22,0,[]],[x22ab\u003Cb\u003Ecya\u003C\/b\u003Ex22,0,[]]],
{x22jx22:x22dx22,x22qx22:x22t8z6h8KhWvbkEX6xablxgYxDUq4x22,x22tx22:
{x22bpcx22:false,x22tlwx22:false}}]"}
/*""*/
{e:"XteVUYKqDoKHrAfdz4D4Aw",c:-1,u:"https://www.google.com/searchdata?hlx3denx26gs_rnx3d14x26gs_rix3dpsy-abx26tokx3dvsobDhICRmdcnY7ayKTGngx26cpx3d2x26gs_idx3ddx26xhrx3dtx26qx3dabx26es_nrsx3dtrue
x26pfx3dpx26outputx3dsearchx26sclientx3dpsy-abx26oqx3dx26gs_lx3dx26pbxx3d1x26bavx3don.2,or.r_cp.r_qf.x26bvmx3dbv.46751780,d.bmkx26fpx3d2647af89de6b6c61x26biwx3d1366x26bihx3d453x26tchx3d1x26echx3d2x26psix3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",
p:true,d:"{x22snpx22:1}"}
/*""*/
  1. Are those hex codes or what do you call them?
  2. Why is there a need for 2 objects to be returned?
  3. What is the need for encoding the JSON?
  4. Which is the ideal format for JSON among these three?

Any thoughts on this are welcome.

1

JSONP is not technically a thing, it’s actually just Javascript. So it’s not JSON but Javascript object initializers.

If you notice, Google’s response does not run as Javascript code nor is it valid JSON. So it doesn’t do anything if a 3rd party site
includes it as a script. Those are not 2 JSON objects for sure because the keys are not quoted. They are Javascript
object initializers which have a property that contains a JSON string that can be parsed as JSON.

You can get the JSON out of the first part like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>var res = '{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hl\x3den\x26gs_rn\x3d14\x26gs_ri\x3dpsy-ab\x26tok\x3dvsobDhICRmdcnY7ayKTGng\x26cp\x3d2\x26gs_id\x3dd\x26xhr\x3dt\x26q\x3dab\x26es_nrs\x3dtrue\x26pf\x3dp\x26output\x3dsearch\x26sclient\x3dpsy-ab\x26oq\x3d\x26gs_l\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_cp.r_qf.\x26bvm\x3dbv.46751780,d.bmk\x26fp\x3d2647af89de6b6c61\x26biw\x3d1366\x26bih\x3d453\x26tch\x3d1\x26ech\x3d2\x26psi\x3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[\x22ab\x22,[[\x22ab\\u003Cb\\u003Ec\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ec news\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Eercrombie\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ecya\\u003C\\/b\\u003E\x22,0,[]]],{\x22j\x22:\x22d\x22,\x22q\x22:\x22t8z6h8KhWvbkEX6xablxgYxDUq4\x22,\x22t\x22:{\x22bpc\x22:false,\x22tlw\x22:false}}]"}'
console.log(JSON.parse(eval("(" + res + ")" ).d));
</code>
<code>var res = '{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hl\x3den\x26gs_rn\x3d14\x26gs_ri\x3dpsy-ab\x26tok\x3dvsobDhICRmdcnY7ayKTGng\x26cp\x3d2\x26gs_id\x3dd\x26xhr\x3dt\x26q\x3dab\x26es_nrs\x3dtrue\x26pf\x3dp\x26output\x3dsearch\x26sclient\x3dpsy-ab\x26oq\x3d\x26gs_l\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_cp.r_qf.\x26bvm\x3dbv.46751780,d.bmk\x26fp\x3d2647af89de6b6c61\x26biw\x3d1366\x26bih\x3d453\x26tch\x3d1\x26ech\x3d2\x26psi\x3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[\x22ab\x22,[[\x22ab\\u003Cb\\u003Ec\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ec news\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Eercrombie\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ecya\\u003C\\/b\\u003E\x22,0,[]]],{\x22j\x22:\x22d\x22,\x22q\x22:\x22t8z6h8KhWvbkEX6xablxgYxDUq4\x22,\x22t\x22:{\x22bpc\x22:false,\x22tlw\x22:false}}]"}' console.log(JSON.parse(eval("(" + res + ")" ).d)); </code>
var res = '{e:"XteVUYKqDoKHrAfdz4D4Aw",c:0,u:"https://www.google.com/s?hl\x3den\x26gs_rn\x3d14\x26gs_ri\x3dpsy-ab\x26tok\x3dvsobDhICRmdcnY7ayKTGng\x26cp\x3d2\x26gs_id\x3dd\x26xhr\x3dt\x26q\x3dab\x26es_nrs\x3dtrue\x26pf\x3dp\x26output\x3dsearch\x26sclient\x3dpsy-ab\x26oq\x3d\x26gs_l\x3d\x26pbx\x3d1\x26bav\x3don.2,or.r_cp.r_qf.\x26bvm\x3dbv.46751780,d.bmk\x26fp\x3d2647af89de6b6c61\x26biw\x3d1366\x26bih\x3d453\x26tch\x3d1\x26ech\x3d2\x26psi\x3dVteVUcYuzOGsB6LpgdgB.1368774484351.1",p:true,d:"[\x22ab\x22,[[\x22ab\\u003Cb\\u003Ec\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ec news\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Eercrombie\\u003C\\/b\\u003E\x22,0,[]],[\x22ab\\u003Cb\\u003Ecya\\u003C\\/b\\u003E\x22,0,[]]],{\x22j\x22:\x22d\x22,\x22q\x22:\x22t8z6h8KhWvbkEX6xablxgYxDUq4\x22,\x22t\x22:{\x22bpc\x22:false,\x22tlw\x22:false}}]"}'

console.log(JSON.parse(eval("(" + res  + ")" ).d));

Note that I added additional slashes so that the initial res would be exactly the same because it goes through additional string interpolation that it otherwise wouldn’t go through.

A third party website can’t extract the contents of the script, they can only run it. If Google just included JSON directly, then a 3rd party site could just override Object/Array constructors and access your data.

See

http://www.lazycoder.com/weblog/2007/04/02/ajax-library-security-advisory/

http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx

http://jeremiahgrossman.blogspot.fi/2006/01/advanced-web-attack-techniques-using.html

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật