This assignment involves building a tool that analyzes a JSON document and infers its schema.
Write a program that takes a JSON file as an argument and performs the following:
- Reads the JSON document from the provided file.
- Analyzes the document structure to identify the schema (attribute names).
- For each attribute in the schema, infers its data type based on the values present in the document.
- String
- Number (Integer or Float)
- Boolean
- Array (collection of values of the same or different types)
- Object (nested structure)
The program should display the inferred schema in a user-friendly format.
Here’s an example:
- name: (String)
- age: (Number)
- hobbies: (Array of Strings)
- address: (Object)
- street: (String)
- city: (String)
- zip: (String)
You must implement this tool in C/C++. Here are some key points to consider:
- Use SimdJson for parsing JSON data.
- Documentation of the library and quick start can be found here.
- Recursively traverse the JSON document to explore nested structures.
- During traversal, keep track of encountered attributes and their corresponding values.
- Based on the value types encountered (string, number, boolean, array, object), infer the data type for each attribute.
- A recursive example of processing a JSON document can be found here:
recursive_print_json example
Your program will be evaluated based on the following criteria:
- Correctness: Does the program accurately identify the schema and infer data types?
- Readability: Is the code well-structured and easy to understand?
- Bonus: Points will be awarded for error handling and additional features.
- Start by working on simple JSON documents and gradually increase complexity.
- Use debugging tools to inspect the structure of the JSON data during traversal.
- You can use the example code (quickstart) to see how to use the library in Visual Studio.
- You can work in teams.
To compile:
g++ quickstart.cpp simdjson.cpp Add all files to the project