I needed a JSON parser for my server to parse the configurations and other JSON files. I decided to make my own JSON parser because I used other open source ones and they weren't fit for my style of coding. I needed a JSON parser which could directly parse the JSON file from a string and could also retransform the data map into a JSON string.
To begin this development, I started by reading the JSON specification. Then I made diagrams of the algorithms I would use to parse the JSON file. I made diagrams for the base algorithm, the string algorithm, the value algorithm, the array algorithm, and the number algorithm.
Algorithms
These algorithms are based on the JSON graphs on json.org and adapted for this project.
json.org
Base algorithm
String algorithm
Value Algorithm
Array algorithm
Number algorithm
For this development, I wanted to do test-driven development (TDD). I started by writing some tests for the JSON parser. I wrote basic tests for different types of JSON values, such as strings, numbers, arrays, and objects. I also wrote tests for nested JSON objects and arrays. After writing the tests, I wrote the JSON parser.
I never did TDD before, so it was a new experience for me. I found it very interesting, because I had to think about what the JSON parser should do before writing the code. I had to think about the different cases and how the JSON parser should handle them. I also had to think about the different types of JSON values and how the JSON parser should parse them.