0

Following are my JSON data :

[
    {
        "items": [
            {
                "retailername": "Zop Now",
                "value": 475
            },
            {
                "retailername": "Snap Deal",
                "value": 265
            },
            {
                "retailername": "Natures Basket",
                "value": 86
            }
        ]
    }
]

What I want is:

[
    {
        "retailername": "Zop Now",
        "value": 475
    },
    {
        "retailername": "Snap Deal",
        "value": 265
    },
    {
        "retailername": "Natures Basket",
        "value": 86
    }
]

That much of part from above data.

Thanks in advance.

3
  • 1
    I'd love to see your own efforts first. Commented Sep 12, 2016 at 10:29
  • First thanx for your good advise. I have try. I have also try following two answers but it's show me undefined error. Commented Sep 12, 2016 at 11:22
  • You should post the code you're using. Even if you're getting an error. Commented Sep 12, 2016 at 11:23

5 Answers 5

1

Check this:

var data = [{"items":[{"retailername":"Zop Now","value":475},{"retailername":"Snap Deal","value":265},{"retailername":"Natures Basket","value":86}]}]

var items = data[0]["items"];

console.log(items);

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Vijay.. It's give me undefined output.
@Tanisha - please console.log(data) first. If its gives you correct output then above code should work. Please share your code.
1

Something like this should do what you expect :

var jsonbase = [{
  "items": [{
    "retailername": "Zop Now",
    "value": 475
  }, {
    "retailername": "Snap Deal",
    "value": 265
  }, {
    "retailername": "Natures Basket",
    "value": 86
  }]
}];



var json = jsonbase[0].items;

console.log(json);

https://jsfiddle.net/Tintin37/scuozurn/

1 Comment

Hi Quentin.. It's give me undefined output.
0

Try following:

let data, arr;
    data = [{"items":[{"retailername":"Zop Now","value":475},{"retailername":"Snap Deal","value":265},{"retailername":"Natures Basket","value":86}]}];
    arr = [];
    for(let i =0; i < data.length; i++){
        if(data[i].hasOwnProperty('items') && data[i].items instanceof Array){
            arr.push(data[i].items);
        }
    }
    console.log(arr);

Comments

0

var obj = [{
  "items": [{
    "retailername": "Zop Now",
    "value": 475
  }, {
    "retailername": "Snap Deal",
    "value": 265
  }, {
    "retailername": "Natures Basket",
    "value": 86
  }]
}];



var getJson = obj[0]['items']; //or

var get_Json = obj[0].items;

console.log(getJson) // or ;
   console.log(get_Json);

https://jsfiddle.net/36e91rr4/1/

2 Comments

above code returns - [Object { retailername="Zop Now", value=475}, Object { retailername="Snap Deal", value=265}, Object { retailername="Natures Basket", value=86}]
try it like this console.log(getJson) // or ; console.log(get_Json);
0

If you are still getting errors, probably you do not have a valid javascript object, and it might be in string format.

try

var obj = JSON.parse(your_original_object);

and Then,

var get_Json = obj[0].items;

should give you the object you are looking for.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.