1

I'm fetching product details using an API which gives the response as a JSON object.

{
    "productBaseInfo": {
        "productIdentifier": {
            "productId": "EKTDDD23232zYHR94E4",
        },
        "productAttributes": {
            "title": "Nova KT 72BC 1 Electric Kettle",
            "imageUrls": {
                "400x400": "http://img5a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-400x400-imadddh2fdvuzpxz.jpeg",
                "75x75": "http://img6a.flixcart.com/image/electric-kettle/4/e/4/nova-kt-722-c-kt-722c-75x75-imadddh2fdvuzpxz.jpeg",
            },
            "sellingPrice": {
                "amount": 599.0,
                "currency": "INR"
            },
            "productUrl": "http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=userid"
        }
    }
}

Now I want to get the productId, title in ProductAttributes, and all the image urls and productURL. I tried

var productURL = JSON["productAttributes"].productUrl 

But it returns an error productUrl not found error. Looking for suggestion on how to extract the data. Thanks in advance.

1 Answer 1

3

productAttributes is inside productBaseInfo. So you need to access it like this

console.log(JSON.productBaseInfo.productAttributes.productUrl);
// http://dl.mykart.com/dl/nova-kt-722c-1-electric-kettle/p/itmdddf398rhhhz2?pid=EKTDDDEGXYHR94E4&affid=nikhilgeo
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply. I tried this out but I'm getting an error " TypeError: Cannot read property 'productAttribures' of undefined.
Can you show the actual code which you tried? I think you are getting it as a string.
Hey I got it right I forgot to convert the json object to javascript object. Now it works fine.. Thank you very much
In case of imageurls: To retrive it I used jsObject.productBaseInfo.productAttributes.imageUrls.400*400; but node.js shows SyntaxError:Unexpected token ILLEGAL error at 400*400. How could I get image link with out refering to 400*400
@NikhilGeorge * is not a valid character for an attribute name, so you should access it like this jsObject.productBaseInfo.productAttributes.imageUrls["400*400"]

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.