i'm currently working on a project in Typescript & React which takes an incoming JSON File and converts it to use it for jsonforms. I don't have any influence of the json structure so i have to find a way to convert it properly. The incoming Json looks like the following:
Input
"availableProperties":[ {"name":"color","type": "string","allowed_values": [] }, {"name":"size","type": "string","allowed_values": ["small","medium","large"] }, {"name":"amount","type": "number","allowed_values": [] }
as i want to use jsonforms i need this:
Output
properties: { color:{ type: 'string' }, size:{ type: 'string', enum: ["small","medium","large"] }, amount:{ type: 'number' }}
the input has an array which appears always with same entries. i need to iterate through that (but thats not the problem). my Idea is to create a new Dictionary called "properties" while iterating through the input i have to create a new JSON object which has the key as named in the "name" property of the input. Underneath that i need a new key with the name type which will always be the same and pick the value from the input. in addition to that, if the "allowed_values" has entries in the input then create an enum-key with an array which holds the values from the input.
I tried different approaches with iterating through the input. But i have a major issue in building that new structure.The input structure is parsed via an interface:
interface inputProps { name: string; type: string; allowed_values?: string[];}
which is hold by an parent interface which will be parsed from the JsonFile
export interface ProjectInput { inputProperties: inputProps[];}
parsing the input in this interface structure is working fine as mentioned. But building the new JSON Structure is not working.
Hope Somebody has an idea
Thanks to all in advance