JSON challenge
Hello folks,
I have an JSON object that need to be updated before being parsed into a JSX component.
Source JSON obj:
var Obj = { "data": [ {"id":1, "text":"Task #1", "project":"10", "sub_project":"10-1" }, {"id":2, "text":"Task #2", "project":"10", "sub_project":"10-1" }, {"id":3, "text":"Task #3", "project":"11", "sub_project":"11-1" }, ]};
Required JSON obj result:
var Obj = { "data": [ {"id":10, "text":"Project 10" }, {"id":11, "text":"Project 11" }, {"id":10-1, "text":"Sub Project 10-1", "project":"10" }, {"id":11-1, "text":"Sub Project 11-1", "project":"11" }, {"id":1, "text":"Task #1", "project":"10", "sub_project":"10-1" }, {"id":2, "text":"Task #2", "project":"10", "sub_project":"10-1" }, {"id":3, "text":"Task #3", "project":"11", "sub_project":"11-1" },
What's the best way to update this JSON object "data" to return the required result. The JSON source has only tasks items, but need to include/append all projects and sub-projects (unique values).