diff --git a/JsonParser/.cache-main b/JsonParser/.cache-main index 895879f..394e08c 100644 Binary files a/JsonParser/.cache-main and b/JsonParser/.cache-main differ diff --git a/JsonParser/newfile.json b/JsonParser/newfile.json new file mode 100644 index 0000000..91ae689 --- /dev/null +++ b/JsonParser/newfile.json @@ -0,0 +1 @@ +{"1":2,"3":[-1,2,-3.005640e+00,4.356560e+00],"hello":true} \ No newline at end of file diff --git a/JsonParser/src/com/api/Jasp.scala b/JsonParser/src/com/api/Jasp.scala index 4cb3fb7..52e2374 100644 --- a/JsonParser/src/com/api/Jasp.scala +++ b/JsonParser/src/com/api/Jasp.scala @@ -27,22 +27,39 @@ import com.json.traits.JsonFactory import com.json.traits.JsonMapTrait import com.json.traits.JsonMapTrait import com.json.traits.JsonFactory +import com.json.traits.JsonNumberTrait +import com.json.traits.JsonStringTrait +import com.json.traits.JsonBoolTrait +import com.json.traits.JsonMapTrait +import com.json.traits.JsonMapTrait +import com.json.traits.JsonListTrait +import com.json.traits.JsonListTrait +import com.json.traits.JsonBoolTrait +import com.json.traits.JsonNumberTrait +import com.json.traits.JsonStringTrait +import java.nio.channels.FileChannel +import java.util.RandomAccess +import java.io.RandomAccessFile +import java.nio.ByteBuffer +import com.json.traits.JsonWriteable +import java.io.BufferedOutputStream +import java.io.FileOutputStream object Jasp { - - private val defaultInstance = JsonPrototypeFactory.getInstance( new JsonObject(),new JsonArray(),new JsonNumber(0),new JsonString(null),new JsonBoolean(false)) + + private val defaultInstance = JsonPrototypeFactory.getInstance(new JsonObject(), new JsonArray(), new JsonNumber(0), new JsonString(null), new JsonBoolean(false)) // THE IMPLICIT ARE ALWAYS BOUND TO THE CURRENT FACTORY OBJECT THAT CREATES THE OBJECTS BASED ON USER IMPLEMENTATION // OR WITH DEFAULT SUPPORTED BY THE LIBRARY - implicit def numtoValue(a: Double): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonNumberEntity(a) - implicit def numtoKey(a: Double): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonNumberEntity(a) - implicit def stringtoValue(a: String): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonStringEntity(a) - implicit def stringtoKey(a: String): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonStringEntity(a) - implicit def booltoKey(a: Boolean): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonBooleanEntity(a) - implicit def booltoValue(a: Boolean): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonBooleanEntity(a) - implicit def numtoKeyArrowAssoc(a: Double): ArrowAssoc[JsonKey] = new ArrowAssoc(a) - implicit def stringtoKeyArrowAssoc(a: String): ArrowAssoc[JsonKey] = new ArrowAssoc(a) - implicit def booleantoKeyArrowAssoc(a: Boolean): ArrowAssoc[JsonKey] = new ArrowAssoc(a) + implicit def num2Value(a: Double): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonNumberEntity(a) + implicit def num2Key(a: Double): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonNumberEntity(a) + implicit def string2Value(a: String): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonStringEntity(a) + implicit def string2Key(a: String): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonStringEntity(a) + implicit def bool2Key(a: Boolean): JsonKey = JsonPrototypeFactory.getCurrentInstance().createJsonBooleanEntity(a) + implicit def bool2Value(a: Boolean): JsonValue = JsonPrototypeFactory.getCurrentInstance().createJsonBooleanEntity(a) + implicit def num2KeyArrowAssoc(a: Double): ArrowAssoc[JsonKey] = new ArrowAssoc(a) + implicit def string2KeyArrowAssoc(a: String): ArrowAssoc[JsonKey] = new ArrowAssoc(a) + implicit def boolean2KeyArrowAssoc(a: Boolean): ArrowAssoc[JsonKey] = new ArrowAssoc(a) object JSON { @@ -114,6 +131,19 @@ object Jasp { jsonBool))(fromFile) } + + def toFile(jsonObject: JsonWriteable, filename: String) = { + try { + val target = new BufferedOutputStream( new FileOutputStream(filename) ); + jsonObject.getStringStream().foreach(s => target.write(s.getBytes) ) + target.close() + } catch { + case e: FileNotFoundException => + Logger.error("File $filename not found"); throw e + case e: IOException => Logger.error("Something went wrong when writing file"); throw e + } + } + } } diff --git a/JsonParser/src/com/json/basic/JsonArray.scala b/JsonParser/src/com/json/basic/JsonArray.scala index fdb6bf6..c353fb0 100644 --- a/JsonParser/src/com/json/basic/JsonArray.scala +++ b/JsonParser/src/com/json/basic/JsonArray.scala @@ -16,11 +16,13 @@ import com.json.traits.JsonWriteable object JsonArray { def apply(a1: JsonValue, a2: JsonValue*) = new JsonArray(a1 +: a2) def apply(value: Seq[JsonValue] = Nil) = new JsonArray(value) + implicit def value2Array(a:JsonValue) = a match { case e:JsonArray => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } class JsonArray(value: Seq[JsonValue] = Nil) extends JsonListTrait(value) { override def toString() = "[" + value.mkString(",") + "]" - override def copy(v: Any) = new JsonArray(v.asInstanceOf[Seq[JsonValue]]) + override def copy(v: Seq[JsonValue]) = new JsonArray(v) def this(a1: JsonValue, a2: JsonValue*) = this(a1 +: a2) diff --git a/JsonParser/src/com/json/basic/JsonBoolean.scala b/JsonParser/src/com/json/basic/JsonBoolean.scala index c1d9ca4..805c346 100644 --- a/JsonParser/src/com/json/basic/JsonBoolean.scala +++ b/JsonParser/src/com/json/basic/JsonBoolean.scala @@ -2,14 +2,17 @@ package com.json.basic import com.json.traits.JsonBoolTrait import com.json.traits.JsonWriteable +import com.json.traits.JsonValue object JsonBoolean{ def apply(b:Boolean) = new JsonBoolean(b) + implicit def value2Boolean(a:JsonValue) = a match { case e:JsonBoolean => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } class JsonBoolean(b:Boolean) extends JsonBoolTrait(b) { override def toString() = b.toString() - override def copy(v:Any) = new JsonBoolean(v.asInstanceOf[Boolean]) + override def copy(v:Boolean) = new JsonBoolean(v) } diff --git a/JsonParser/src/com/json/basic/JsonNumber.scala b/JsonParser/src/com/json/basic/JsonNumber.scala index c8ada77..2226ebc 100644 --- a/JsonParser/src/com/json/basic/JsonNumber.scala +++ b/JsonParser/src/com/json/basic/JsonNumber.scala @@ -14,11 +14,13 @@ import com.json.traits.JsonWriteable object JsonNumber { def apply(value: Double) = new JsonNumber(value) + implicit def value2Number(a:JsonValue) = a match { case e:JsonNumber => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } case class JsonNumber(value: Double) extends JsonNumberTrait(value) { override def toString() = value.toString() - override def copy(v: Any) = new JsonNumber(v.asInstanceOf[Double]) + override def copy(v: Double) = new JsonNumber(v) } diff --git a/JsonParser/src/com/json/basic/JsonObject.scala b/JsonParser/src/com/json/basic/JsonObject.scala index a4126b2..b1afcba 100644 --- a/JsonParser/src/com/json/basic/JsonObject.scala +++ b/JsonParser/src/com/json/basic/JsonObject.scala @@ -17,12 +17,14 @@ import com.json.traits.JsonWriteable object JsonObject{ def apply(value:Map[JsonKey , JsonValue] = Map()) = new JsonObject(value) def apply(args:(JsonKey,JsonValue)*) = new JsonObject(args.toMap) + implicit def value2Map(a:JsonValue) = a match { case e:JsonObject => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } class JsonObject(value:Map[JsonKey , JsonValue] = Map()) extends JsonMapTrait(value) { override def toString() = "{"+value.toList.map(f => f._1 + ":" + f._2).mkString(",\n")+"}" - override def copy(v:Any) = new JsonObject(v.asInstanceOf[Map[JsonKey,JsonValue]]) + override def copy(v:Map[JsonKey , JsonValue]) = new JsonObject(v) def this(args:(JsonKey,JsonValue)* ) = this(args.toMap) diff --git a/JsonParser/src/com/json/basic/JsonString.scala b/JsonParser/src/com/json/basic/JsonString.scala index b17ea16..2a8850d 100644 --- a/JsonParser/src/com/json/basic/JsonString.scala +++ b/JsonParser/src/com/json/basic/JsonString.scala @@ -2,6 +2,7 @@ package com.json.basic import com.json.traits.JsonStringTrait import com.json.traits.JsonWriteable +import com.json.traits.JsonValue /** * :JsonString => string @@ -10,11 +11,11 @@ import com.json.traits.JsonWriteable object JsonString{ def apply(value:String) = new JsonString(value) + implicit def value2String(a:JsonValue) = a match { case e:JsonString => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } case class JsonString(value:String) extends JsonStringTrait(value) { override def toString() = if(value == null) "undefined" else "\""+value+"\"" - override def copy(v:Any) = new JsonString(v.asInstanceOf[String]) - - + override def copy(v:String) = new JsonString(v) } \ No newline at end of file diff --git a/JsonParser/src/com/json/traits/JsonBoolTrait.scala b/JsonParser/src/com/json/traits/JsonBoolTrait.scala index 89e0b75..960f1dd 100644 --- a/JsonParser/src/com/json/traits/JsonBoolTrait.scala +++ b/JsonParser/src/com/json/traits/JsonBoolTrait.scala @@ -1,11 +1,15 @@ package com.json.traits abstract class JsonBoolTrait(b:Boolean) extends JsonValue with JsonKey{ - override def copy(a:Any):JsonBoolTrait + def copy(a:Boolean):JsonBoolTrait override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonBooleanTrait does not supports apply, try getValue()") - override def apply(key:Int):JsonValue = throw new IllegalAccessException("JsonBooleanTrait does not supports apply, try getValue()") - override def getValue() = b + override def getValue():Boolean = b override def getStringStream() = Stream(b.toString()) +} + +object JsonBoolTrait { + implicit def value2Bool(a:JsonValue) = a match { case e:JsonBoolTrait => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } \ No newline at end of file diff --git a/JsonParser/src/com/json/traits/JsonListTrait.scala b/JsonParser/src/com/json/traits/JsonListTrait.scala index cf5bbee..2955fde 100644 --- a/JsonParser/src/com/json/traits/JsonListTrait.scala +++ b/JsonParser/src/com/json/traits/JsonListTrait.scala @@ -1,15 +1,26 @@ package com.json.traits abstract class JsonListTrait(value:Seq[JsonValue]) extends JsonUnit with JsonValue { - override def copy(a:Any):JsonListTrait + def copy(a:Seq[JsonValue]):JsonListTrait - override def apply(key:Int):JsonValue = value.applyOrElse(key, null) - override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonArrayTrait does not supports apply on JsonKey, try getValue()") - override def getValue() = value + override def apply(key:JsonKey):JsonValue = key match { + case key:JsonNumberTrait => value.applyOrElse(key.getValue().toInt, null) + case _ => throw new IllegalArgumentException("Non JsonNumber argument given ") + } + + override def getValue():Seq[JsonValue] = value override def getStringStream() = { - Stream("[")++value.toStream.flatMap(f => f.getStringStream() ++ Stream(","))++Stream("]") + (value.toStream.flatMap(f => Stream(",")++f.getStringStream())) match { + case Stream() => Stream("[")++Stream("]") + case v => Stream("[")++v.tail++Stream("]") + } } +} + +object JsonListTrait { + implicit def value2Array(a:JsonValue) = a match { case e:JsonListTrait => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } \ No newline at end of file diff --git a/JsonParser/src/com/json/traits/JsonMapTrait.scala b/JsonParser/src/com/json/traits/JsonMapTrait.scala index 4f6f435..d9ce3c3 100644 --- a/JsonParser/src/com/json/traits/JsonMapTrait.scala +++ b/JsonParser/src/com/json/traits/JsonMapTrait.scala @@ -2,16 +2,33 @@ package com.json.traits //import scala.collection.mutable.HashMap abstract class JsonMapTrait(value:Map[JsonKey , JsonValue]) extends JsonUnit with JsonValue { - override def copy(a:Any):JsonMapTrait + + def copy(a:Map[JsonKey , JsonValue]):JsonMapTrait + override def apply(key:JsonKey) = value.get(key).getOrElse(null) - override def apply(int:Int) = throw new IllegalAccessException("JsonMapTrait does not supports apply on Int, try getValue()") - override def getValue():Map[JsonKey,JsonValue] = value + + override def getValue():Map[JsonKey,JsonValue] = value override def getStringStream() = { - Stream("{") ++ value.toStream.flatMap(f => f._1.getStringStream()++Stream(":")++f._2.getStringStream() ++ Stream(",")) ++ Stream("}") + + (value.toStream.flatMap(f => { + val v = f._1 match { case e:JsonStringTrait => e.getStringStream(); + case e => Stream("\"")++e.getStringStream()++Stream("\"") } + + Stream(",")++ v ++ Stream(":")++f._2.getStringStream()} + )) match { + case Stream() => Stream("{") ++ Stream("}") + case v => Stream("{")++v.tail++Stream("}") + } + } } + +object JsonMapTrait { + implicit def value2Map(a:JsonValue) = a match { case e:JsonMapTrait => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} +} diff --git a/JsonParser/src/com/json/traits/JsonNumberTrait.scala b/JsonParser/src/com/json/traits/JsonNumberTrait.scala index 7019062..7f947e9 100644 --- a/JsonParser/src/com/json/traits/JsonNumberTrait.scala +++ b/JsonParser/src/com/json/traits/JsonNumberTrait.scala @@ -1,12 +1,22 @@ package com.json.traits abstract class JsonNumberTrait(num:Double) extends JsonKey with JsonValue { - override def copy(a:Any):JsonNumberTrait + def copy(a:Double):JsonNumberTrait override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonNumberTrait does not supports apply, try getValue()") - override def apply(key:Int):JsonValue = throw new IllegalAccessException("JsonNumberTrait does not supports apply, try getValue()") - override def getValue() = num - - override def getStringStream() = Stream(num.toString()) + override def getValue():Double = num + override def getStringStream() = Stream( this.printDouble(num)) + + private def printDouble(a:Double) = { + if(a < Int.MaxValue ) + if((a - a.toInt) != 0) f"$a%e" else a.toInt.toString() + else + f"$a%e" + } + +} +object JsonNumberTrait { + implicit def value2Number(a:JsonValue) = a match { case e:JsonNumberTrait => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} } \ No newline at end of file diff --git a/JsonParser/src/com/json/traits/JsonStringTrait.scala b/JsonParser/src/com/json/traits/JsonStringTrait.scala index 923e956..7070f72 100644 --- a/JsonParser/src/com/json/traits/JsonStringTrait.scala +++ b/JsonParser/src/com/json/traits/JsonStringTrait.scala @@ -1,10 +1,9 @@ package com.json.traits abstract class JsonStringTrait(str:String) extends JsonKey with JsonValue { - override def copy(a:Any):JsonStringTrait - override def getValue():String = str + def copy(a:String):JsonStringTrait + override def getValue():String = str override def apply(key:JsonKey):JsonValue = throw new IllegalAccessException("JsonStringTrait does not supports apply, try getValue()") - override def apply(key:Int):JsonValue = throw new IllegalAccessException("JsonStringTrait does not supports apply, try getValue()") override def getStringStream() = { Stream("\""+str+"\"") @@ -13,3 +12,8 @@ abstract class JsonStringTrait(str:String) extends JsonKey with JsonValue { } +object JsonStringTrait { + implicit def value2String(a:JsonValue) = a match { case e:JsonStringTrait => e; + case _ => throw new ClassCastException("Cannot cast "+a.getClass +" to "+this.getClass)} +} + diff --git a/JsonParser/src/com/json/traits/JsonUnit.scala b/JsonParser/src/com/json/traits/JsonUnit.scala index 6d8e335..80fb48b 100644 --- a/JsonParser/src/com/json/traits/JsonUnit.scala +++ b/JsonParser/src/com/json/traits/JsonUnit.scala @@ -1,7 +1,6 @@ package com.json.traits -trait JsonUnit { +trait JsonUnit{ override def toString():String def getValue():Any - def copy(a:Any):JsonUnit } \ No newline at end of file diff --git a/JsonParser/src/com/json/traits/JsonValue.scala b/JsonParser/src/com/json/traits/JsonValue.scala index 3b3e8e4..ba6bd3a 100644 --- a/JsonParser/src/com/json/traits/JsonValue.scala +++ b/JsonParser/src/com/json/traits/JsonValue.scala @@ -2,5 +2,4 @@ package com.json.traits trait JsonValue extends JsonUnit with JsonWriteable { def apply(key:JsonKey):JsonValue - def apply(key:Int):JsonValue } diff --git a/JsonParser/src/com/lexer/analyzer/LexemeGenerator.scala b/JsonParser/src/com/lexer/analyzer/LexemeGenerator.scala index 6e19b5c..1048ea6 100644 --- a/JsonParser/src/com/lexer/analyzer/LexemeGenerator.scala +++ b/JsonParser/src/com/lexer/analyzer/LexemeGenerator.scala @@ -104,6 +104,7 @@ class LexemeGenerator(tokens: => Stream[TextToken]) extends LexemeGeneratorTrait // Check for number + case (`stateS`,v) if (v == '-') => (state3,false,buffer.append(v), prevlexArray) case (`stateS`,v) if (v.isDigit) => (state3,false,buffer.append(v),prevlexArray) case (`state3`,v) if (v.isDigit) => (state3,false,buffer.append(v),prevlexArray) case (`state3`,v) if (v == '.') => (state4,false,buffer.append(v),prevlexArray) diff --git a/JsonParser/src/com/lexer/lexicon/BooleanLexeme.scala b/JsonParser/src/com/lexer/lexicon/BooleanLexeme.scala index 8925f01..4552c9b 100644 --- a/JsonParser/src/com/lexer/lexicon/BooleanLexeme.scala +++ b/JsonParser/src/com/lexer/lexicon/BooleanLexeme.scala @@ -6,11 +6,11 @@ import com.lexer.traits.SymbolTable import com.logger.Logger class BooleanLexeme(b:String, lineNumber:Int, columnNumber:Int) extends Lexeme with SymbolTable { - def getValue():Boolean = try { b.toBoolean } - catch{ - case e:Exception => Logger.error("Something wrong with Lexeme have bad string data for boolean "+b) - throw e - } + def getValue():Boolean = try { b.toBoolean } + catch{ + case e:Exception => Logger.error("Something wrong with Lexeme have bad string data for boolean "+b) + throw e + } def getSymbol() = this.BOOL def getLineNumber():Int = lineNumber def getColumnNumber():Int = columnNumber diff --git a/JsonParser/src/com/parser/director/ParseTable.scala b/JsonParser/src/com/parser/director/ParseTable.scala index c72d322..df9dd1c 100644 --- a/JsonParser/src/com/parser/director/ParseTable.scala +++ b/JsonParser/src/com/parser/director/ParseTable.scala @@ -62,7 +62,7 @@ trait ParseTable extends SymbolTable { case (stackSymb,lex) if (stackSymb == lex) => stack.tail case _ =>try{ - throw new IllegalStateException("expected "+stack.head+"found '"+lexeme.getValue()+"' cannot parse Json, illegal symbol at (l,c):"+lexeme.getLineNumber()+":"+lexeme.getColumnNumber()) + throw new IllegalStateException("Look ahead or action for "+stack.head+" not found on '"+lexeme+"' cannot parse Json, illegal symbol at (l,c):"+lexeme.getLineNumber()+":"+lexeme.getColumnNumber()) }catch{ case e:IllegalAccessError => throw new IllegalStateException("found '"+lexeme.getSymbol()+"' cannot parse Json, illegal symbol at (l,c):"+lexeme.getLineNumber()+":"+lexeme.getColumnNumber()+"\n"+e) } diff --git a/JsonParser/src/com/parser/director/Parser.scala b/JsonParser/src/com/parser/director/Parser.scala index 3116246..122c011 100644 --- a/JsonParser/src/com/parser/director/Parser.scala +++ b/JsonParser/src/com/parser/director/Parser.scala @@ -7,9 +7,7 @@ import com.file.tokenizer.Tokenizer import com.lexer.traits.LexemeGeneratorTrait class Parser(lexer:LexemeGeneratorTrait, builder:JsonBuilderTrait) extends ParseTable{ - - - + def parse() = { val stack = lexer.getStream().foldLeft(List(this.S,this.STOP))((stack,lexeme) => { this.stackOperation(stack, lexeme , builder) diff --git a/JsonParser/src/com/unit/test/Main.scala b/JsonParser/src/com/unit/test/Main.scala index a76e03a..acdcf39 100644 --- a/JsonParser/src/com/unit/test/Main.scala +++ b/JsonParser/src/com/unit/test/Main.scala @@ -6,6 +6,10 @@ import com.json.basic.JsonObject import com.json.basic.JsonArray import com.json.traits.JsonUnit import com.json.basic.JsonString +import com.json.basic.JsonNumber +import com.json.basic.JsonBoolean +import com.json.traits.JsonNumberTrait +import com.json.traits.JsonStringTrait /** * Benchmark with citylots.json : Elapsed time: 227.2318s @@ -26,22 +30,25 @@ object Main { def main(args: Array[String]): Unit = { val filename = "E://Project Work//citylots.json" val filename2 = "E://Project Work//JASP_Another_Json_Scala_Parser//JsonParser//test.json" - val filename3 = "E://Project Work//JASP_Another_Json_Scala_Parser//JsonParser//test2.json" - -// val a = Logger.timer( JSON.parseFile(filename3) ) + val newfile = "E://Project Work//JASP_Another_Json_Scala_Parser//JsonParser//newfile.json" + + val a = Logger.timer( JSON.parseFile(filename2) ) + + print(a("context")("date")) + + val map = JsonObject(1 -> 2 , 3 -> JsonArray(-1.00,2.00,-3.00564,4.35656) , "hello" -> JsonBoolean(true) ) + + println(map) + + val str = map.getStringStream().toList mkString "" + + println(str) + + val smap = JSON.parseString(str) + - - - val map = JsonObject( - 1 -> JsonArray(1, 2, 3, "Hello", false), - 3 -> JsonArray(JsonObject(1 -> 2, 3 -> 4), 3, 4, "false", false)) - - var head2 = map.getStringStream() - for(i <- 1 to 10){ - print(head2.head) - head2 = head2.tail - } + JSON.toFile(smap, newfile) diff --git a/README.md b/README.md index 7010b41..5a3ece3 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,33 @@ object Main { * */ - val map = JsonObject(1 -> JsonArray(1,2,3,"Hello",false), - 3 -> JsonArray(JsonObject(1->2,3->4),3,4,"false",false)) - println(map) - + val a = Logger.timer( JSON.parseFile(filename2) ) + + print(a("context")("date")) + + + // This pretty syntax alas is only possible in Scala with tons of implicits + // You can also have compile time type safety because of the same. Though ugly conversions are there just hidden + + val map:JsonMap = JsonObject(1 -> 2 , 3 -> JsonArray(-1.00,2.00,-3.00564,4.35656) , "hello" -> JsonBoolean(true) ) + + + println(map) + + // A lazy stream based iterator is returned by each JsonUnit since they all implement JsonWritable interface + + val str = map.getStringStream().toList mkString "" + + println(str) + + // You can also directly pass a valid string and have it parsed there itself + + val smap = JSON.parseString(str) + + // You can now write to file + + JSON.toFile(smap, newfile) } @@ -64,7 +86,7 @@ You can run the above for testing the package by changing the filename , * **Create a iiterator or a stream for a walk on the JSON**: A tree structure need to be enforced in the JSON structure for it to be walked on The Writable iterator is a very specific usecase of the same. -* ~~**Create a lazy writable iterator for the JSON objects**~~ Create a fast writer consumer for the writables. +* ~~**Create a lazy writable iterator for the JSON objects**~~ ~~Create a fast writer consumer for the writables.~~ * ~~**Turn this project into a Maven Artifact Library**~~