0
  1. I have a json like below..after fetching this json i stored in one variable called data.I need to change this data variable as bellow

      {
    "recipes": [
    {
    "cuisine": "chinese",
    "description": "hjkhdkd",
    "id": 3,
    "min_time": "30-60min",
    "name": "Noodles",
    "nutrition": "",
    "qty": "",
    "quantity_unit_id": "2",
    "rate": "",
    "recipe_type": "vegetarian",
    "serve": [
    "4"
    ],
    "tip": "",
    "image_url": {
    "medium": "/system/recipes/images/000/000/003/medium/dfdfs.jpeg?1501851554"
    }
    }
    ]
    }
    
  2. how i can change above json data like bellow using javascript

    [
    {
    "cuisine": "chinese",
    "description": "hjkhdkd",
    "id": 3,
    "min_time": "30-60min",
    "name": "Noodles",
    "nutrition": "",
    "qty": "",
    "quantity_unit_id": "2",
    "rate": "",
    "recipe_type": "vegetarian",
    "serve": [
    "4"
    ],
    "tip": "",
    "image_url": {
    "medium": "/system/recipes/images/000/000/003/medium/dfdfs.jpeg?1501851554"
    }
    }
    ]
    
1
  • 3
    data = data.recipes Commented Oct 18, 2017 at 4:32

1 Answer 1

1
var data = '{ "recipes": [ { "cuisine": "chinese", "description": "hjkhdkd", "id": 3, "min_time": "30-60min", "name": "Noodles", "nutrition": "", "qty": "", "quantity_unit_id": "2", "rate": "", "recipe_type": "vegetarian", "serve": [ "4" ], "tip": "", "image_url": { "medium": "/system/recipes/images/000/000/003/medium/dfdfs.jpeg?1501851554" } } ] }';
var jsonifieddata = JSON.parse(data);
var newdata = jsonifieddata.recipes;
JSON.stringify(newdata);

Run this in your console.

A suggestion: share some effort you have made when you ask on stackoverflow again.

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

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.