Javascript Create Json
I'm trying to create and post a json message in the following format:
var listObjects = [];
$.each(results, function(index, value){
var item = new Object();
item.title = value.Title;
item.code = value.Code;
listObjects.push(item);
});
var jsonResult = JSON.strringify(listObjects);
basically this will create my json like this:
[{"title":"Product 1","code":123456789012},
{"title":"Product 2","code":123456789012},
{"title":"Product 3","code":123456789012},
{"title":"Product 4","code":123456789012},
{"title":"Product 5","code":123456789012},
{"title":"Product 11","code":123456789012},
{"title":"Product 12","code":123456789012},
{"title":"Product 13","code":123456789012}]
how can I do it so that if I want to add some metadata to my json that
will not repeat for each item but just at the top ... something like this:
category: x
type: y
...
items:
title: .....
code: ......
so basically the category and type will define the whole items in the json
but are not repeated for each item ...
No comments:
Post a Comment