I am retrieving list item values in sharepoint using REST API.

Now I want to store these values in JSON so I can just call the JSON and retrieve the values in another function

    url: lib,
    method: 'GET',
    async: false,
    headers: {"accept":"application/json;odata=verbose"},
    success: function(data) {
        /* console.log(data); */
        if(data.d != undefined) {
            var temp_prod= [];
            $.each(data.d.results, function (i,item) {

        } });

I want to construct the JSON to be like this

var products = [{ Dell Laptop: { price: 1000.00, color: black },
                  HP Laptop: { price: 900.00, color: grey }]

and can I access these using

var dellLaptopPrice = products["Dell Laptop"].price;
var dellLaptopColor = products["Dell Laptop"].color;

1 Answer 1


got it using this code

var products = {}

$.each(data.d.results, function (i,item) {
      products[item.Name] = {name: item.Name, price: item.Price, color: item.Color }


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.