Hello guys I am having some trouble trying to parse out the returned JSON data from a dijit search. I have the following code where s.set("value","48035") will be populated from another page so for the time being i manually set it to 48035.

    var s = new Search({
        enableButtonMode: true, //this enables the search widget to display as a single button
        enableLabel: false,
        enableInfoWindow: true,
        showInfoWindowOnSelect: false,
        map: map
    }, "search");

    s.set("value", "48035");

//have tried the following
    s.search().then(function (response) {
        var extra = response[0][0].x
//and the following
s.search().then(function (response) {
                var extra = response.candidates[0].location

It seems like no matter what i try or do i can not figure out how to get the returned value of x. Here is what the returned JSON data looks like.

{"spatialReference":{"wkid":4326,"latestWkid":4326},"candidates":[{"address":"48035, Clinton Township
, Michigan","location":{"x":-82.9172080701955,"y":42.554260928999781},"score":100,"attributes":{"Addr_type"
:"Postal","Match_addr":"48035, Clinton Township, Michigan","StAddr":"","City":"Clinton Township"},"extent"

1 Answer 1


You should import the json module from Dojo. It will allow you to create a JavaScript object from your return JSON and do what you want with it.

So, if you want to create a Geometry object, you can parse the returned JSON with the json module, get your JavaScript object, and create it from the properties of the derived JavaScript object.

Say your object is named returnJSON and you want to create a Point from it.

var returnJSON = JSON.parse(response.candidates[0]);

var x = returnJSON.location.x;
var y = returnJSON.location.y;

//then create your point or whatever you want to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.