yet a simple JSON Schema extracting and flatting tool implemented by Scala
gaebolg means "spear of mortal pain/death", was the name of the spear of Cúchulainn in the Ulster Cycle of Irish mythology.
一个简单的基于Scala实现的JSON Schema的提取和展开的工具
gaebolg的意思是致命之枪,取自爱尔兰神话 Ulster Cycle
Current features include:
- generate JSON schema from a set of JSON instances
- from JSON schema instance to
String
and vice versa - flat a JSON schema and transform it into a set of
ExecutableTableNode
目前的功能:
- 从一组JSON实例中生成一个JSON schema
- 字符串与JSON schema的互转
- 将一个JSON schema 转成一组
ExecutableTableNode
currently depends on following libs:
- gaebolg uses json4s to do JSON related operation
- gaebolg uses scalaz for functional operation support
目前依赖以下库:
Currently, in my company, there are lots of data stored as JSON, including but not limited to MongoDB,App logs. JSON now is popular with the whole world and more and more people become familiar with it, but there comes a so wired requirement that we have to transform json and flat it into several tables based on relational database model... Large quantities of table and lack of time, we need to find some ways to make this process more automatic instead of manually making the JSON schema, flatting the JSON data according to the schema. What's worse, for some reason, no one knows the precise JSON schema(seems terribly annoying,huh). So I made this tool to help me easily generate and flat json schema and hope to make json data flatting automatically.
First,let me clarify some concepts
- JSON AST
the following code is the AST which models the structure of a JSON document as a syntax tree
sealed abstract class JValue
case object JNothing extends JValue // 'zero' for JValue
case object JNull extends JValue
case class JString(s: String) extends JValue
case class JDouble(num: Double) extends JValue
case class JDecimal(num: BigDecimal) extends JValue
case class JInt(num: BigInt) extends JValue
case class JLong(num: Long) extends JValue
case class JBool(value: Boolean) extends JValue
case class JObject(obj: List[JField]) extends JValue
case class JArray(arr: List[JValue]) extends JValue
type JField = (String, JValue)
json4s is strictly implemented the JSON AST which can be used easily, based on this JSON AST, gaebolg designs and implements its own JSON Schema
-
JSON Schema
this is core concepts in gaebolg. A set of JSON can be described as a complicated JSON Schema which contain a lot of JSON schema content
we got 9 kind of JSON Schema:
- ArraySchema -> JArray
- ObjectSchema -> JObject
- StringSchema -> JString
- NumberSchema -> JDouble/JDecimal
- IntegerSchema -> JInt/JLong
- BooleanSchema -> JBool
- ZeroSchema -> JNothing
- NullSchema -> JNull
- ProductSchema -> [*]
productSchema is a special case, it is for multiple schemas in the same position(always happen in merge schema)
//todo
//todo
-
First of all, really appreciate schema-guru, which inspiring gaebolg a lot
-
thanks 4 wenjin's advice on writing format
-
首先,非常感谢schema-guru,受了很多启发
-
感谢文瑾的英文书写建议