Problem 4
Create a Form from a JSON Payload
Write a script that can iterate over a JSON object of any shape and return the following:
- if you find a string return 'text-input'
- if you find integer return 'number-input'
- if you find an object return 'object' and iterate over it finding strings, integers or lists
- if you find an list return 'list' and iterate over it finding strings, integers or objects
Notes
- The JSON payload may be of any shape.
- Data may be nested
- This data will be used to build an HTMl form, so get the values as well as the keys so that the values can be nested under the keys as sections in the form
Questions
- Should you use recursion or iteration?
- What other checks should be done?
json
{
"squadName": "Super hero squad",
"homeTown": "Metro City",
"formed": 2016,
"secretBase": "Super tower",
"active": true,
"members": [
{
"name": "Molecule Man",
"age": 29,
"secretIdentity": "Dan Jukes",
"powers": ["Radiation resistance", "Turning tiny", "Radiation blast"]
},
{
"name": "Madame Uppercut",
"age": 39,
"secretIdentity": "Jane Wilson",
"powers": [
"Million tonne punch",
"Damage resistance",
"Superhuman reflexes"
]
},
{
"name": "Eternal Flame",
"age": 1000000,
"secretIdentity": "Unknown",
"powers": [
"Immortality",
"Heat Immunity",
"Inferno",
"Teleportation",
"Interdimensional travel"
]
}
]
}
Approach
What is your approach on solving this problem?
Solution
Solution
Solution