javascript - Converting JSON to have a new top-level wrapper -


i suspect using wrong terminology, please bear me.

i have been using mustache.js work json output of api. working sibling api has outlook looks similar, excepting there no top-level name. trying figure out how adjust new json output other format, such can continue using mustache.js approach (this seems easier of options, other being using other mustache.js, seeking avoid).

i can use mustache.js iterate on following json body using top-level name 'records':

{"records": [{"dt_created":"08/23/2013 04:49:13 pm","created_by":"x,   x","dt_updated":"08/23/2013 04:49:13 pm","updated_by":"x, x","field_60374":  ["project 67"],"field_60331":["ability adjust number of lines dynamically based on   mood of person 3 rows down, 4th cube, 11th building. breakthrough in mind-control   data processing."],"field_60333":   [{"id":"x","first":"x","last":"x"}],"field_60394":  [{"id":"x","first":"x","last":"x"}],"field_60414":["11"],"field_60375":  ["22"],"field_60395":["a"],"record_id":"1920704","form_id":"10898"}, {"dt_created":"08/23/2013 04:47:45 pm","created_by":"x, x","dt_updated":"08/23/2013 04:47:45 pm","updated_by":"x, x","field_60374":["project 2"],"field_60331":["very cool project allow more single invoice in erp @ 1 time. quite big leap forward."],"field_60333": [{"id":"x","first":"x","last":"x"}],"field_60394": [{"id":"x","first":"x","last":"x"}],"field_60414":["x,  x"],"field_60375":["60"],"field_60395": ["a"],"record_id":"1920703","form_id":"10898"}], "meta":{"total":2,"count":2} } 

the format can't iterate through, since missing top-level name, is:

[{"id":"x","user": {"id":"x","first_name":"x","last_name":"x"},"title":"test post 3","text":"this equally cool , enthralling post.","created_at":"2013-08-29t17:46:04.801z","updated_at":"2013-08-29t17:46:04.804z","num_comments":0,"num_likes":0}, {"id":"y","user":   {"id":"212342277","first_name":"x","last_name":"x"},"title":"test post 1","text":"super cool content want read!","created_at":"2013-08- 29t17:44:58.188z","updated_at":"2013-08-29t17:44:58.190z","num_comments":0,"num_likes":0}] 

i tried following massage second json example format of first:

$.ajax({      […….],      success: function(json_data){                         alert("success");                              var template=$('#listposts').html();                         var stuff = {"records":json_data}; //here                         var stuff = json.stringify(stuff); //here                         alert(stuff);                            //var html = mustache.to_html(template, json_data);                         var html = mustache.to_html(template, stuff);                         //$('.content-pane').empty();                                                                                                                                                        $('#listofpostscontainer').html(html);  } } 

i have alert pops in var 'stuff', , seems formatted first json example, mustache.js doesn't parse (i have verified mustache.js executes). before trying address other issues, wanted understand if how adding top-level name json array in above ajax call success attribute correct, or if have differently.

if missing explain this, let me know, can add it.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -