Skip to content

RobertFischer/json-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Parser

This is a JavaCC-derived JSON parser. It is crazy fast and fault tolerant, but with no bells or whistles. The intent is for this to form the backbone for other JSON-consuming libraries like Resty.

Faults Tolerated

None of the following is legitimate JSON code, yet you will find it in the wild. This library parses them 'correctly' (at least, insofar as standards-violating processing can be 'correct').

  • C-style and SH-style Comments - e.g. /* ... */, // ..., # ...

  • Bareword Keys - Yup, that's invalid JSON. For reals.

  • Ruby Symbols - Because they're pervasive bugs across the internet.

  • Large Numerical Value Support - Not technically a fault, but most libraries parse integers and decimals using doubles or longs, which can be a problem if you have large values in your JSON. This library uses BigDecimal and BigInteger by default for more accurate parsing. You can shift to using double and long values by setting the parser.nativeNumbers property, but if you are thinking about setting that flag for performance reasons, you're almost certainly doing it wrong.

Usage

Here's a minimal example:

import org.fogbeam.json.parser.JSONParser;

public class Foo {
	public static void main(String[] args) {
		System.out.println("Parsed value: " + new JSONParser(args[0]).parse());
	}
}

Also available on the JSONParser class:

  • InputStream and Reader constructors - For your consuming convenience
  • parseObject() - Parses a JSON object into a LinkedHashMap
  • parseArray() - Parses a JSON array into an ArrayList

License

CC0
To the extent possible under law, Robert Fischer has waived all copyright and related or neighboring rights to JSON Parser. This work is published from: United States.

About

JavaCC-built JSON Parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages