News for hackers. Stuff that matters.
Re:Parsing JSON is a Minefield by ben_jones on Wednesday October 26, 2016 @01:43PM (#12798661)
Silent moment for those of us using niche languages to meet production requirements in environments that do not allow third-party code and do not have JSON parsing in the std lib...
Re:Parsing JSON is a Minefield by jfoutz on Wednesday October 26, 2016 @03:05PM (#12799423)
If you don't have a solution, or you're not happy with your current solution, take a look at parsec style parsing. you can make a lot of progress with just a few combinators, and those style parsers are pretty easy to read.

You can get an implementation working with a fairly high level of confidence that it's right.

If it's not fast enough, make a pretty printer for your AST. Then do a CPS transform (by hand) on your library and parser, so you can make the stack explicit. Make sure the transformed version pretty prints exactly the same way.

Then make a third version that prints out the code that should run when parsing a document, rather than doing the parsing directly. You'll get a big case switch for each grammar you want to parse. Your pretty printer will help you find many bugs.

It's a pretty achievable path to get your grammar correct, and then get a specialized parser for it.

Re:Parsing JSON is a Minefield by oblio on Wednesday October 26, 2016 @01:51PM (#12798744)
If your language doesn't come with JSON in the stdlib, you're really on the cutting edge. Or using a language meant for embedding :)
Re:Parsing JSON is a Minefield by grondo4 on Wednesday October 26, 2016 @04:33PM (#12800203)
Doesn't Java lack a JSON parser in the standard library?
Re:Parsing JSON is a Minefield by amake on Thursday October 27, 2016 @12:20AM (#12802883)
As of Java 8, the Nashorn JavaScript engine is included by default, and it does support JSON parsing.

[1] http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/

Re:Parsing JSON is a Minefield by prodigal_erik on Wednesday October 26, 2016 @05:23PM (#12800723)
The standard Java library includes a JavaScript interpreter, so there has to be a parser for object literals in there somewhere.
Re:Parsing JSON is a Minefield by tree_of_item on Wednesday October 26, 2016 @06:37PM (#12801351)
Object literals aren't JSON, though.
Re:Parsing JSON is a Minefield by Volt on Wednesday October 26, 2016 @11:17PM (#12802675)
JS has stringify and parse, so there ought to be a JSON parser somewhere.
Re:Parsing JSON is a Minefield by dfox on Thursday October 27, 2016 @01:22AM (#12803093)
One thing that the article mentions is that there are in fact strings that are valid JSON but not valid JS object literals.
Re:Parsing JSON is a Minefield by Macha on Saturday October 29, 2016 @07:30AM (#12823528)
https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...

A modern JS implementation should also have a JSON parser

Re:Parsing JSON is a Minefield by int_19h on Thursday October 27, 2016 @12:20AM (#12802884)
> you're really on the cutting edge.

Or the other way around. Think about something like MUMPS.

Re:Parsing JSON is a Minefield by differentman on Friday October 28, 2016 @11:13AM (#12816682)
No, no thank you. Did it for a year. Pretty sure I don't even want to think about doing it again.
Re:Parsing JSON is a Minefield by thechao on Wednesday October 26, 2016 @03:44PM (#12799768)
Pour a 40 for me; I shall go wallow in my assembly shame.