Using JSON (Bing, Version 2)

The Bing JSON interface is an HTTP GET interface which accepts search requests in URL format and returns search results in JSON format.

Sending a Request in URL Format

In order to use the JSON interface, you need to know is how to submit a search request in URL format.

When a search request is submitted in URL format, each URL parameter presents a field in the search request. A simple search request that returns a Web result and a Spell result could look like this:

http://api.bing.net/json.aspx?AppId= YOUR_APPID &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&Web.Count= 1

AppId, Version, Market, Query, and Sources are the first-level fields of SearchRequest object, which can be directly specified as URL parameters. Simple types like AppId can be specified by the syntax Field**=Value. However, array types such as Sources, the list of SourceType enumerations, should be separated by +. Thus, the syntax will look like Field=Value1+Value2++ValueN. In addition, to specify the value of fields in a structure type, like Count in WebRequest, the . operator is used to access sub-fields with the syntax Field.SubField=**Value.

Note: Arrays of arrays or structures are not supported in the request interface of Bing API 2.0. For arrays of strings, space in each string must be encoded. For example, use %20 as opposed to +.

For details of search request and response objects, refer to the following topics:

Using JSONType

For the JSON interface, there is an interface-specific parameter JsonType, which can control the format of the response. If raw enumeration is specified, search results are returned in pure JSON format. If callback enumeration is specified, a JavaScript statement will be returned to call the callback function specified in the JsonCallback parameter and search results will be passed in as arguments. If the function enumeration is specified, a JavaScript function will be returned and the search results will be returned when the function is invoked. The following sections give an example request and response for each of these options.

Raw Enumeration Example

Request

http://api.bing.net/json.aspx?AppId= YOUR_APPID &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&Web.Count=1&JsonType=raw

Note: For information about obtaining an AppId, see Bing Developer Center.

Response

{
   "SearchResponse":{
      "Version":"2.2",
      "Query":{
         "SearchTerms":"testign"
      },
      "Spell":{
         "Total":1,
         "Results":[
            {
               "Value":"testing"
            }
         ]
      },
      "Web":{
         "Total":5100,
         "Offset":0,
         "Results":[
            {
               "Title":"Testign part 2 - Tiernan OTooles Programming Blog",
               "Description":"If this works, it means nothing really, but i have managed to build a .TEXT blog posting app. could be handy if i move my main blog to .TEXT, which i am thinking about..",
               "Url":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
               "DisplayUrl":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
               "DateTime":"2008-10-21T05:08:05Z"
            }
         ]
      }
   }
}

Function Enumeration Example

Request

http://api.bing.net/json.aspx?AppId= YOUR_APPID &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&Web.Count=1&JsonType=function

Note: For information about obtaining an AppId, see Bing Developer Center.

Response

function LiveSearchGetResponse(){
   return{
      "SearchResponse":{
         "Version":"2.2",
         "Query":{
            "SearchTerms":"testign"
         },
         "Spell":{
            "Total":1,
            "Results":[
               {
                  "Value":"testing"
               }
            ]
         },
         "Web":{
            "Total":5100,
            "Offset":0,
            "Results":[
               {
                  "Title":"Testign part 2 - Tiernan OTooles Programming Blog",
                  "Description":"If this works, it means nothing really, but i have managed to build a .TEXT blog posting app. could be handy if i move my main blog to .TEXT, which i am thinking about..",
                  "Url":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
                  "DisplayUrl":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
                  "DateTime":"2008-10-21T05:08:05Z"
               }
            ]
         }
      }/*pageview_candidate*/
   };
}

Callback Enumeration Example

Request

http://api.bing.net/json.aspx?AppId= YOUR_APPID &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&Web.Count=1&JsonType=callback&JsonCallback=UserCallback

Note: For information about obtaining an AppId, see Bing Developer Center.

Response

if(typeofUserCallback=='function')UserCallback({
   "SearchResponse":{
      "Version":"2.2",
      "Query":{
         "SearchTerms":"testign"
      },
      "Spell":{
         "Total":1,
         "Results":[
            {
               "Value":"testing"
            }
         ]
      },
      "Web":{
         "Total":5100,
         "Offset":0,
         "Results":[
            {
               "Title":"Testign part 2 - Tiernan OTooles Programming Blog",
               "Description":"If this works, it means nothing really, but i have managed to build a .TEXT blog posting app. could be handy if i move my main blog to .TEXT, which i am thinking about..",
               "Url":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
               "DisplayUrl":"http:\/\/weblogs.asp.net\/tiernanotoole\/archive\/2004\/09\/24\/233830.aspx",
               "DateTime":"2008-10-21T05:08:05Z"
            }
         ]
      }
   }/*pageview_candidate*/
});