r/sfdc • u/nil_von_9wo • May 11 '18
Writing a complicated JSON parser in APEX
This blog on writing a simple JSON parser in Python was relatively linked to /r/programming: http://notes.eatonphil.com/writing-a-simple-json-parser.html
Because I have more time than sanity, I decided to write a JSON parser in Apex.
Just to make things a little more interesting, I decided to write this in highly OOP style borrowing several ideas from functional programming (e.g. scala; specifically immutable maps, immutable lists, option type).
It was particularly interesting to deal with the recursion issues.
For several reasons (not the least of which, SFDC already gives us a more efficient, more functional JSON parser), this shouldn't be used in any production environments, but if anyone is curious to take a look, you'll find the solution at:
https://github.com/nilvon9wo/ApexJsonParser
(On the TODO list: replacing for and while control structures with recursive method calls.)