{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Some modern nonrelational database systems like

Info iconThis preview shows pages 2–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ceiving data. Some modern, nonrelational database systems like CouchDB and MongoDB either use JSON or formats inspired by JSON as their encoding for data. JSON has also seen adoption among scientists, businesses, and others as a simple format for storing any kind of data for later use. Why has JSON become so popular so quickly? JSON addresses many of the problems that people have with other popular formats for data interchange, particularly XML. First off, JSON is designed to be completely human-readable – JSON documents are simple and are easy to format for display. While many formats like XML are also written in plain text, heavier syntax and a larger set of features give a lower ratio of information to boilerplate than JSON. Another consequence of JSON’s simple syntax and feature set is that JSON is simpler to parse and produce than other formats. Lightweight syntax also means that JSON documents can usually encode more information in less space than equivalent documents in other formats, saving time and often money when documents are sent over the network or read from disk. A JSON document is either a JSON object mapping keys to JSON values or an array of JSON values. A JSON value can be one of 7 things: 1. Nothing at all (this is the “value” in an empty array or object) 2. A number, e.g, 42 or 3.14 3. A string, e.g., "Hello world" or ’Hello world’ 4. A boolean, either true or false 2
Background image of page 2

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
5. An array, an ordered sequence of JSON values in brackets, e.g., [42, true, ’Hello’] 6. An object, which is an unordered collection of string keys and JSON values (with a colon after each key, and comma between all pairs) in curly braces, e.g., { "ready": true, "answer": 42 } An example JSON document: { "cis": [ { "name": "CIS120", "instructor": "Dr. Weirich", "languages": ["OCaml", "Java"] }, { "name": "CIS121", "instructor": "Dr. Tannen", "languages": ["Java"] } ] } To parse JSON, you will be using GSON, an open source Java library for reading and writing JSON developed by Google. A jar file for GSON is included in the provided files. To add the jar to your project in Eclipse, right-click the name of your project in the navigator pane and select “Properties”. Select the “Java Build Path” option, then choose the “Libraries” tab. From here, you can click the “Add External JARs”, select the file gson-2.2.2.jar and click OK. You can read JavaDocs for GSON at http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html. In the provided files, there is also a sample class that uses GSON to parse the above example document. 2.2 Friend.java and FakebookReader.java 20pts To start off, you will write a class FakebookReader.java that, given the name of a file containing a friend graph encoded as JSON, will produce a friend graph using the provided Friend class. (You may, though do not need to, implement a toString or compareTo for Friend. We will not test either method - this is solely for your own use. You must submit Friend.java regardless). Read the comments in the provided skeleton code for FakebookReader to determine what methods you must implement. Additionally, you will want to read the documentation for the GSON class JsonReader before you get started. Pay attention to the beginObject and endObject methods (to use a JsonReader, you will have to import com.google.gson.stream.JsonReader).
Background image of page 3
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}