Parsing JSON with a single regex

For my presentation to the Houston Perl mongers tonight, I'm talking about Randal Schwartz's regex to parse JSON.

5 Comments

Very cool. Are there other parsers implemented as a single regex (I guess Regexp::Grammar-based ones count too)? I'll be starting a quest to catalog those.

This is quite awesome, just another reason why Perl's regular expression capabilities are still unmatched.

Awesome. XML parser next?

I have been promising for 2 years a YAPC::NA that I will finish up my giant XML Regex and get it on CPAN (I'm leaning towards ACME::XML:RegEx for a name)

I think I've managed to get a standards complaint expression for standalone="yes" documents, but the second you throw in an external subset a static parse is impossible. The parsing rules become dependent on the semantic meaning of previously parsed tokens.

if you want to beautify your code for in proper format or minify then you can use

http://codebeautify.org/view/jsonviewer

to beautify and get new way to display your code easily

Leave a comment

About brian d foy

user-pic I'm the author of Mastering Perl, and the co-author of Learning Perl (6th Edition), Intermediate Perl, Programming Perl (4th Edition) and Effective Perl Programming (2nd Edition).