# JSON solutions ## Exercise 1 Write a JSON that stores the following information (a different JSON for each item) 1. A student named Joan Garcia from València and his birth date is 24th of February. ```json { "name": "Joan", "surname": "Garcia", "city": "València", "birth_date": { "day": 24, "month": 02 (or "February") } } ``` 2. A list of the following restaurants: - Bar Pasqual is a tapes bar in Av. Blsco Ibáñez, 232, València. Its owner is Marc Alcover. - Restaurant Meravelles is a menu restaurant located in Av. Regne de València, 111, València, owned by Maria Pasqual. - Racó de l'Avia is a menu restaurant in Av Roma, 221, Barcelona owned by Alba Puig. ```json { "establishments": [ { "name": "Bar Pasqual", "type": "tapes", "address": { "street": "Av. Blasco Ibáñez", "number": 232, "city": "València" }, "owner": "Marc Alcover" }, { "name": "Restaurant Meravelles", "type": "menu", "address": { "street": "Av. Regne de València", "number": 111, "city": "València" }, "owner": "Maria Pasqual" }, { "name": "Racó de l'Àvia", "type": "menu", "address": { "street": "Av. Roma", "number": 221, "city": "Barcelona" }, "owner": "Alba Puig" } ] } ``` 3. A list of art from a museum: - "Der Kuss" its a painting from Gustav Klimt painted in 1907. - "Gernica" its a mural from Pablo Picasso painted in 1937. - "David" its a marble sculpture from Michelangelo created in 1504. ```json { "artworks": [ { "name": "Der Kuss", "type": "painting", "year": 1907, "author": "Gustav Klimt" }, { "name": "Gernica", "type": "mural", "year": 1937, "author": "Pablo Picasso" }, { "name": "David", "type": "marble sculpture", "year": 1504, "author": "Michelangelo" } ] } ``` ## Exercise 2 Write a JSON document with the same information and structure than the following XML document. ```xml <widget> <debug>on</debug> <window title="Sample Konfabulator Widget"> <name>main_window</name> <width>500</width> <height>500</height> </window> <image src="Images/Sun.png" name="sun1"> <hOffset>250</hOffset> <vOffset>250</vOffset> <alignment>center</alignment> </image> <text data="Click Here" size="36" style="bold"> <name>text1</name> <hOffset>250</hOffset> <vOffset>100</vOffset> <alignment>center</alignment> <onMouseUp> sun1.opacity = (sun1.opacity / 100) * 90; </onMouseUp> </text> </widget> ``` - Solution: ```json { "widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": "500", "height": "500" }, "image": { "src": "Images/Sun.png", "name": "sun1", "hOffset": "250", "vOffset": "250", "alignment": "center" }, "text": { "data": "Click Here", "size": "36", "style": "bold", "name": "text1", "hOffset": "250", "vOffset": "100", "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" } } } ``` ## Exercise 3 The following JSON provides information about the bicycle service in Barcelona: http://wservice.viabicing.cat/v2/stations Write: - The street name of the station with id 33. - How many bycicles are available in the station in Girona, 68 in this moment? Append a screenshot of the JSON fragment where you found this information. ```json { "stations": [ ... { "id":"33", "type":"BIKE", "latitude":"41.376862", "longitude":"2.190773", "streetName":"Pontevedra ", <- This is the street name "streetNumber":"58B", "altitude":"1", "slots":"21", "bikes":"0", "nearbyStations":"33"," status":"CLS" }, ... { "id":"15", "type":"BIKE", "latitude":"41.394812", "longitude":"2.171189", "streetName":"Girona", <- Street name "streetNumber":"68", <- Street number "altitude":"40", "slots":"18", "bikes":"0", <- Current bikes "nearbyStations":"15", "status":"CLS" }, ... ] } ``` ## Exercise 4 - Write a JSON that stores the information about cooking recipes. - Store 2 recipes at least - The JSON document must have at least 4 levels. ``` { "recipes" : [ { "name": "Arròs al forn", "ingredients": [ { "name": "rice", "quantity": "250g", }, { "name": "potato", "quantity": "2 units", }, ... ], "steps": [ "Prepare the ingridients", "Heat the oven", ... ] }, { "name": "Pizza", "ingredients": [ { "name": "Chesse", "quantity": "250g", }, { "name": "Tomato", "quantity": "2 units", }, ... ], "steps": [ "Prepare the ingridients", "Heat the oven", ... ] }, ] } ```