Skip to content

Simple JSON serializer with nice formatting written in Scala

License

Notifications You must be signed in to change notification settings

BartekBH/JSON-serializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON serializer written in Scala, which provides converters for:

  • Int
  • Float
  • Double
  • Boolean
  • Char
  • String
  • List
  • Array

For custom types you need to define custom implicit converter, e.g.

implicit object UserConverter extends JSONConverter[User] {
def convert(user: User): JSONValue = JSONObject(Map(
"name" -> JSONString(user.name),
"age" -> JSONInt(user.age),
"email" -> JSONString(user.email)
))
}

Then you can call stringify on your custom type to see result:

val john = User("John", 34, "[email protected]")
println(john.toJSON.stringify)

Result:

{
    "name": "John",
    "age": 34,
    "email": "[email protected]"
}

Look at Example.scala for more detailed example.

About

Simple JSON serializer with nice formatting written in Scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages