0

I need to parse the below json and display in a html page.

  1. Display COLA, COLB, COLC in a dropdownlist
  2. display the values of type and index in a html table.

JSON

{
  "mydb1": {
    "mappings": {
      "TAB1": {
        "properties": {
          "COLA": {
            "type": "string",
            "index": "not_analyzed"
          },
          "COLB": {
            "type": "string",
            "index": "not_analyzed"
          },
          "COLC": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    }
  }
}
1
  • did you try researching? Commented Nov 16, 2015 at 10:44

1 Answer 1

1

Try this:

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<div id="dropDown"></div>
<table id='tableVal' border='1'></table>
<script>
  $(document).ready(function() {
    var jsonStr = '{\
            "mydb1": {\
                "mappings": {\
                    "TAB1": {\
                        "properties": {\
                            "COLA": {\
                                "type": "string",\
                                "index": "not_analyzed"\
                            },\
                            "COLB": {\
                                "type": "string",\
                                "index": "not_analyzed"\
                            },\
                            "COLC": {\
                                "type": "string",\
                                "index": "not_analyzed"\
                            }\
                        }\
                    }\
                }\
            }\
        }';
    var jsonObj = JSON.parse(jsonStr);
    var drpDwn = '<select>',
      tabData = '';
    //console.log(jsonObj.mydb1.mappings.TAB1.properties);
    var temp = jsonObj.mydb1.mappings.TAB1.properties;
    $.each(temp, function(str, value) {
      drpDwn += '<option>' + str + '</option>';
      console.log(value.index);
      tabData += '<tr><td>' + value.type + '</td><td>' + value.index + '</td></tr>';
    });
    drpDwn += '</select>';
    $('#dropDown').html(drpDwn);
    $('#tableVal').html(tabData);
    //$.each(jsonObj.)
  });
</script>

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

1 Comment

Very helpful. Thanks a lot Sanjay Kumar N S

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.