How to parse a JSON file using jQuery?

I am making an AJAX call to an API like this,

$.ajax({
        url: 'http://dev.markitondemand.com/MODApis/Api/v2/InteractiveChart/jsonp?parameters={"Normalized":false,"NumberOfDays":1095,"DataPeriod":"Day","Elements":[{"Symbol":"AAPL","Type":"price","Params":["ohlc"]}]}',
        dataType: 'jsonp',
        success: function(data) {
                //output = JSON.stringify(data, null, '\t')
                $('#container').html(JSON.stringify(data.Elements.Currency, null, '\t'));

        }
    });

The resultant JSON file is huge and I want to extract value of Elements->Currency.

What am I doing wrong here?

Answers 1

  • Use the dot notation, no need to stringify the data

    success: function(data) {
                   alert(data.Positions);
            }
    

    or use a loop for elements:

    success: function(data) {
                  $.each(data.Elements,function(i,v){
                     console.log(v.Currency);
                  });
            }
    

    see demo


Related Articles