JSON is a text-based format for structured values. An object contains string keys and values; values may be objects, arrays, strings, numbers, booleans, or null. A parser can first turn a document into a syntax tree without performing further processing. section 9.4.1
A JSON document
A market-data object can contain strings such as "MSFT", booleans such as true, numbers such as 30.66 and 8.38e9, and an array of related company tickers. The corresponding Scala representation uses cases such as JString, JNumber, JBool, JArray, JObject, and JNull. section 9.4.1
Build a JSON parser by composing small parsers and preserving the document’s structure:
- Parse a document as optional leading whitespace followed by an array or object, then require end of input. section 9.8
- Parse arrays as bracketed, comma-separated values and convert the results to JArray. section 9.8
- Parse objects as comma-separated key-value pairs and convert them to JObject. section 9.8
- Parse literals such as null, numbers, quoted strings, true, and false, using token parsers and regular expressions where useful. section 9.8
- Use map, map2, flatMap, many, sep, and choice to combine parsers while discarding separators and retaining meaningful results. section 9.4.2
{
"Company name" : "Microsoft Corporation",
"Ticker" : "MSFT",
"Active" : true,
"Price" : 30.66,
"Shares outstanding" : 8.38e9,
"Related companies" :
[ "HPQ", "IBM", "YHOO", "DELL", "GOOG" ]
}
Inspect a complete JSON example containing nested objects, arrays, strings, booleans, and numbers. section 9.4.1


































