Created
June 20, 2017 07:20
-
-
Save debnath/66fc7e5b960a32a318e728da2054ef6e to your computer and use it in GitHub Desktop.
Organising data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There are 2 possibilities I can think of to organise the data cleanly. | |
Option 1) | |
* Have 2 JSON objects. | |
* One that is just a map between the salad name and the id. We can then pass ids from the form to the calculator functions. | |
* The other json object contains all the actual data. | |
E.g.: | |
{ | |
"chicken & avocado":"1", | |
"roast veggie":"2" | |
} | |
{ | |
"1":{ | |
"small":{ | |
"name":"chicken & avocado", | |
"id":1, | |
"protein":"45g", | |
"energy":{ | |
"cal":250, | |
"kj":1025 | |
} | |
}, | |
"medium":{ | |
"name":"chicken & avocado", | |
"id":1, | |
"protein":"55g", | |
"energy":{ | |
"cal":300, | |
"kj":1225 | |
} | |
} | |
}, | |
"2":{ | |
"small":{ | |
"name":"roast veggies", | |
"id":2, | |
"protein":"45g", | |
"energy":{ | |
"cal":250, | |
"kj":1025 | |
} | |
}, | |
"medium":{ | |
"name":"roast veggies", | |
"id":2, | |
"protein":"55g", | |
"energy":{ | |
"cal":300, | |
"kj":1225 | |
} | |
} | |
} | |
} | |
Option 2) | |
* Have 1 json object. | |
* It looks exactly like the 2nd object from option 1, except instead of being keyed by an ID, it's keyed by the salad name | |
* The downside is it means we'll be passing the salad names to the calculator functions, and that feels a bit hacky. | |
* Alternatively we an still use the integer IDs, but it means parsing a moderately complex json object | |
{ | |
"chicken & avocado":{ | |
"small":{ | |
"id":1, | |
"protein":"45g", | |
"energy":{ | |
"cal":250, | |
"kj":1025 | |
} | |
}, | |
"medium":{ | |
"id":1, | |
"protein":"55g", | |
"energy":{ | |
"cal":300, | |
"kj":1225 | |
} | |
} | |
}, | |
"Roast veggies":{ | |
"small":{ | |
"id":2, | |
"protein":"45g", | |
"energy":{ | |
"cal":250, | |
"kj":1025 | |
} | |
}, | |
"medium":{ | |
"id":2, | |
"protein":"55g", | |
"energy":{ | |
"cal":300, | |
"kj":1225 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment