Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating AVRO schema from JSON Schema File

Tags:

json

avro

avro4s

I have the JSON file & JSON Schema to be parsed into the AVRO Schema. I am little bit confused, do i have to write the manual AVRO schema using the data types defined in AVRO documentation.

Or is there any automated method / function / program that can work exactly the same as required ?

like image 779
user2857762 Avatar asked Apr 18 '16 09:04

user2857762


2 Answers

Well, you can try https://github.com/fge/json-schema-avro, but they say it is still not complete. So not sure it will work, though

like image 99
RadioLog Avatar answered Sep 26 '22 06:09

RadioLog


avro4s derives schemas at compile time from case classes:

import com.sksamuel.avro4s.SchemaFor

object Avro {
  case class MyAvroClass(s: String, i: Int)

  def main(args: Array[String]): Unit = {
    val avroSchema = SchemaFor[MyAvroClass]()
    println(avroSchema.toString(true))
  }
}

Yields:

{
  "type" : "record",
  "name" : "MyAvroClass",
  "namespace" : "tests",
  "fields" : [ {
    "name" : "s",
    "type" : "string"
  }, {
    "name" : "i",
    "type" : "int"
  } ]
}
like image 33
Yuval Itzchakov Avatar answered Sep 26 '22 06:09

Yuval Itzchakov