javascript - JSON to JSON mapping using Mustache -
i want map input json json using mustache
.
my input json like:
{ "data": [ { "catalogid": "1850", "productid": "elec004a"}, { "catalogid": "1851", "productid": "png679"} ] }
i want template in combine mustache tags output json.
var template = json.stringify( { product: [ {{#data}} { productid:'{{productid}}', parentproductid:'{{catalogid}}' } {{/data}} ] } );
i tried using mustache tag json giving me errors. tried defining template without using json.stringify
no luck!
have use mustache requirement, actual input json quite large , can't map using traditional way.
my desired output json mentioned in template mustache tags replaced relevant data input json
you don't need moustache here.
var input = { "data": [ { "catalogid": "1850", "productid": "elec004a"}, { "catalogid": "1851", "productid": "png679"} ] }; var output = { product: input.data.map(item => ({ productid: item.productid, parentproductid: item.catalogid })) }; console.log(output);
Comments
Post a Comment