In this homework, we will learn how to read, process, and output data in different formats.
Write a program called "json2xml" to read data in JSON and output the same data formatted in XML. You should write this program in C++. The program will accept the input in stdin and output the results to stdout. Here is how you might run it:
./json2xml < json-in > xml-out
Writer another program called "xml2json" to read data in XML and output that data in JSON.
./json2xml < json-in > xml-out
Once you have these two programs, you should be able to chain them using pipes as many times as you want without corrupting the data. For example:
./json2xml < json-in | ./xml2json | ./json2xml | ./xml2json > json-out
You can then use the "diff" command to see if the two files are the same:
diff json-in json-out
We would like you to write the data parser on your own (using string tokenizer) so you can understand the challenges in parsing the data. You will also write your own function to output data in the desired format.
To simplify your parser and formatter, we will test your program with a simple JSON and XML files. You should not hard code the number of attributes and their names in your parser and formatter.
Devise a solution so that if you input a wrong format, the program displays an error to stderr (not stdout) and halts:
./json2xml < xml-in Error: input format incorrect
Your submission should be a .tar.gz of the directory where you have your source code and a Makefile. Also include a textfile called README with a short description of how to run the programs, what limitations exist (if any) and a commentary on how you devised a solution to detect input format error and if your solution has any limitation. You will submit your .tar.gz on Moodle.
To grade your submission, we will copy your .tar.gz to bayou, untar, change to that directory and type "make". It should generate two executables json2xml and xml2json.