0

I have json data like this

FixedFields: {
"DocType": {
  "fieldValueOnChange": "",
  "operatorStyle": "width:80%",
  "fieldType": "Fixed",
  "operatorOnChange": "selectFixedFieldType(this);",
  "contextpath": "/iTunes",
  "validations": {
    "alphaNumeric": {

    }
  },
  "fieldValueType": "text",
  "OperatorTypes": {
    "not equals to": "text",
    "equal to": "text",
    "paste list": "textarea",
    "starts with": "text",
    "contains": "text"
  },
  "fieldValueStyle": "width:90%"
},
"Amount": {
  "fieldValueOnChange": "",
  "operatorStyle": "width:80%",
  "fieldType": "Fixed",
  "operatorOnChange": "selectFixedFieldType(this);",
  "contextpath": "/iTunes",
  "validations": {
    "numericDouble": {
      "limit": "16"
    }
  },
  "fieldValueType": "text",
  "OperatorTypes": {
    "equal to": "text",
    "not equals to": "text",
    "between": "textbetween",
    "less than": "text",
    "less than or equal to": "text",
    "greater than": "text",
    "greater than or equal to": "text"
  },
  "fieldValueStyle": "width:35%;"
}
}

The problem is that I would like to identify the label name and value and render in a mustache template and I do not know how the JSON structure from my web service response would look like.

I know it can be done with json parsing by

for(key in array) {...} 

How can I do templating in mustache for whose data i'm not sure of the structure? Thanks in advance

Katakam Nikhil
  • 1,375
  • 4
  • 14
  • 22
  • FYI, "JSON" is a text interchange format. The only place you're using that term correctly in your question is "JSON structure from my web server". Once it is parsed, it is "Javascript data", no longer JSON. And, `for (key in array)` is Javascript, not JSON. – jfriend00 Sep 18 '14 at 15:00
  • We're going to need some more info in order to help. Please show the desired final HTML output from this JSON so we can understand what you are trying to extract from your javascript structure. And, then describe what you do and don't know specifically about the javascript structure. Are you just trying to dump the entire structure into HTML just to see it? Or are you looking for specific fields? And, if you're looking for specific fields, but don't know their names or structure, how do you propose to find the right field in the sea of data? – jfriend00 Sep 18 '14 at 15:03
  • Thank you for the prompt response. All I am trying to do is to render this data with a mustache template The question I have is that if you look at the top of the json data, "DocType" is a label. The problem is that this label name might or might not be consistent. Meaning that i might not get "DocType" again if i make the same web service call. The names of those fields will vary. How do I write my template so I can cater to those varying fields? – Katakam Nikhil Sep 19 '14 at 16:21
  • 1
    Sorry, but it is not clear what you're trying to do. If you just want to display the data structure whatever it is in JSON format, then just do JSON.stringify of the data and pass that string to your template. I'm guessing that you will have to process the data with javascript into a KNOWN format with known keys before you can meaningfully use it in a template. But, I still have no idea what you're actually trying to accomplish. What does "render this data" mean? Please edit your post and show what the result should look like. – jfriend00 Sep 19 '14 at 16:29

0 Answers0