JSON Handler: Implementing a Custom Data Structure for JSON Objects

Verified

Added on  2019/09/13

|3
|836
|367
Practical Assignment
AI Summary
This assignment requires the creation of a custom JSON handler, a data structure designed to reconstitute JSON-encoded objects. The handler must parse JSON strings and implement at least one Java data structure interface. It needs to handle serializable objects, determine if objects implement Comparable, and identify an object's class. The data structure must support adding, retrieving, sorting, and searching for objects, as well as removing specific objects and exporting objects as JSON. The assignment also addresses the handling of nested JSON objects, where values can be other name-value pairs or arrays. The core functionality involves parsing JSON strings using string manipulation techniques, as well as parsing JSON objects and arrays. The goal is to build a robust data structure capable of managing complex JSON data, such as data from database rows.
Document Page
JSON Handler
you are tasked with creating a JSON handler. A JSON stands for JavaScript Object Notation (See: JSON
Description). A JSON is a lightweight data-interchange formatted as a string that can be parsed back into
the object it represents. Your JSON handler will be a custom data structure that will reconstitute the
JSON encoded objects in your data-structure objects. Your data structure must:
1. Add new object
2. Get an object
3. Sort sortable objects
4. Search for a specific value (binary for sortable/linear for un-sortable)
5. Remove a specific object
6. Export an object as a JSON
Your data structure:
Must parse JSON Strings
Must implement at least one java data structure interface
Must handle serializable object (to serialize and de-serialize objects)
Must be able to determine an object if an object implements Comparable
Must be able to determine an object’s class
Objects in Objects
A JSON object may have multiple name-value pairs in it (see: JSON Description). The value in a name-
value pair can be one or more name-value pairs:
{ name : { name : value , name : value } }
For example, imagine that rows from a database are downloaded as JSON objects. Each row would have
the same basic format. Each “name” would be a column and each “value” would be the data in that row
for that column and the main identifier would be the primary key identifying the row.
{ primary key : { “fname” : “fred” , “lname” : “jones” , “age” : “35” , “address” : “123 Main st” }
In this example, there is an object whose “name” is the primary key of a database table and its value is a
separate data structure of four other name-value objects. You might imagine the entire data base table
is a giant data structure of all the “row objects” in the table.
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
JSON Description
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to
read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript
Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is
completely language independent but uses conventions that are familiar to programmers of the C-family
of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties
make JSON an ideal data-interchange language.
JSON is built on two structures: A collection of name/value pairs. In various languages, this is realized as an object, record,
struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. In most languages, this is realized as an array, vector, list, or
sequence.”
-Source: http://www.json.org/
A JSON object can be formatted simply curly braces and a colon similar to the way a key-value object (as
in a hash table) is notated. i.e.: { name : value }
-Source: http://www.json.org/
JSON object can have more than one name-value pair separated by commas.
{ name : value , name2 : value2 }
A JSON array is an ordered (indexed) collection of JSON objects. A JSON array is simply notated with
square brackets with comma separators in between JSON objects.. For example:
[ { name : value } , { name2 : value2 } ]
A JSON array can also have a name of its own:
{ name: [ { name : value } , { name2 : value2 } ] }
In this way a JSON array can be a value in a name-value pair. In fact, a value can be any object. A value
can be another data structure (ArrayList, LinkedList, HashTable, ect.) or an instance of another class.
“A value can be a string in double quotes, or a number, or true or false or null, or an object or an array.
These structures can be nested.” -Source: http://www.json.org/
Document Page
-Source: http://www.json.org/
Parsing JSONs
JSON are strings. Even when the “value” is an object, that object is serialized (convert into a bit string).
You can easily parse strings by using Sting function .split(). You can parse JSON objects by splitting on
the String “:”. You can parse JSON arrays by splitting on the String “,”.
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]