Untitled
unknown
plain_text
2 years ago
726 B
5
Indexable
javascript function transformJson(input) { let output = { "otherAllowedFilters": { "AND": [], "OR": [] } }; input.otherAllowedFilters.forEach(filter => { let newFilter = { ...filter }; if (filter.otherAllowedFilters) { newFilter.otherAllowedFilters = transformJson({ "otherAllowedFilters": filter.otherAllowedFilters }).otherAllowedFilters; } filter.operationsAllowed.forEach(operation => { output.otherAllowedFilters[operation].push(newFilter); }); }); return output; } // Usage let jsonObject1 = { "otherAllowedFilters": [ // ... ] }; let jsonObject2 = transformJson(jsonObject1); console.log(JSON.stringify(jsonObject2, null, 2));
Editor is loading...