samirahmed / supereasy_json_parser

A super easy to use JSON parser written in scala, based on the "Programming in Scala" example and SteveJ's Scala-JSON

Home Page:http://www.samir-ahmed.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README: Super Easy JSON Parser

Designed to be the most simple way to extract data from JSON, the Super Easy JSON Parser is adapted from Martin Odersky's book and the more robust string parsing from scala-json by Steve Jenson.

Values, Objects and Arrays

  • Objects are JSON objects and are represented by Scala Map(String, Any)
  • Arrays are JSON arrays and are represented by Scala List(Any)
  • Values are the data in JSON members {"key":"value"} and most often represented as Strings

Super Easy Methods and examples

Sample JSON File - rawjson.txt

{
     "firstName": "John",
     "lastName": "Smith",
     "age": 25,
	 "hometown":["Brooklyn", "New York"],
     "address":
     {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber":
     [
         {
           "type": "home",
           "number": "212 555-1234"
         },
         {
           "type": "fax",
           "number": "646 555-4567"
         }
     ]
 }

Sample Usage

After calling the parse(rawjson :String) method

getValue("type") 			returns "home" 
getValue("\"type\"")		returns	"home"
getValue("type",2) 			returns "fax"
getAllValues("type") 		returns List("home","fax")
getObject("address")		returns Map("streetAddress"->"21 2nd Street","city"->"New York","State"->"NY","postalCode"->"10021")
getArray("hometown")		returns List("Brooklyn", "New York")

Licensing

	Copyright 2011 Samir Ahmed
	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

   	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.

About

A super easy to use JSON parser written in scala, based on the "Programming in Scala" example and SteveJ's Scala-JSON

http://www.samir-ahmed.com


Languages

Language:Scala 100.0%