All Projects → allegro → Json Avro Converter

allegro / Json Avro Converter

Licence: other
JSON to Avro conversion tool designed to make migration to Avro easier.

Programming Languages

groovy
2714 projects

Projects that are alternatives of or similar to Json Avro Converter

Yii2 Gii
Yii 2 Gii Extension
Stars: ✭ 183 (-1.61%)
Mutual labels:  hacktoberfest
Doctree
Repository of Japanese Ruby reference manual
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Electricalage
Electrical Age (ELN) is a Minecraft Mod offering the ability to perform large-scale in-game electrical simulations.
Stars: ✭ 185 (-0.54%)
Mutual labels:  hacktoberfest
Bundler Leak
Known-leaky gems verification for bundler: `bundle leak` to check your app and find leaky gems in your Gemfile 💎💧
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Linebot
🤖 SDK for the LINE Messaging API for Node.js
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Discordchatexporter
Exports Discord chat logs to a file
Stars: ✭ 3,198 (+1619.35%)
Mutual labels:  hacktoberfest
Px4 Sitl gazebo
Set of plugins, models and worlds to use with OSRF Gazebo Simulator in SITL and HITL.
Stars: ✭ 182 (-2.15%)
Mutual labels:  hacktoberfest
Amazingavatar
An android amazing avatar anim in CollapsingToolbarLayout.
Stars: ✭ 186 (+0%)
Mutual labels:  hacktoberfest
Training Material
A collection of Galaxy-related training material
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Simplepresence
An easy and simple way to set your Discord Rich Presence Status through RPC (no token required)
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Magento2 Menu
Provides powerful menu editor to replace category based menus in Magento 2
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Demo
Demo app for the API Platform framework
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
View component reflex
Stars: ✭ 185 (-0.54%)
Mutual labels:  hacktoberfest
Chef Client
Development repository for Chef Client cookbook
Stars: ✭ 183 (-1.61%)
Mutual labels:  hacktoberfest
Fluentvalidation
A library for using FluentValidation with Blazor
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest
Docker
🐳
Stars: ✭ 183 (-1.61%)
Mutual labels:  hacktoberfest
Optaplanner
AI constraint solver in Java to optimize the vehicle routing problem, employee rostering, task assignment, maintenance scheduling, conference scheduling and other planning problems.
Stars: ✭ 2,454 (+1219.35%)
Mutual labels:  hacktoberfest
Elasticpypi
Serverless pypi
Stars: ✭ 186 (+0%)
Mutual labels:  hacktoberfest
Mockbukkit
MockBukkit is a mocking framework for bukkit to allow the easy unit testing of Bukkit plugins.
Stars: ✭ 186 (+0%)
Mutual labels:  hacktoberfest
Star Battle
🎮 A spaceship shooting game developed using JavaScript ES6, Canvas
Stars: ✭ 184 (-1.08%)
Mutual labels:  hacktoberfest

json-avro-converter

Build Status

This project is a JSON to Avro conversion tool designed to make migration to Avro easier. It includes a simple command line validator.

Motivation

Apache Avro ships with some very advanced and efficient tools for reading and writing binary Avro but their support for JSON to Avro conversion is unfortunately limited and requires wrapping fields with type declarations if you have some optional fields in your schema. This tool is supposed to help with migrating projects from using JSON to Avro without having to modify JSON data if it conforms to the JSON schema.

JSON2Avro Converter

Features

  • conversion of binary JSON to binary Avro
  • conversion of binary JSON to GenericData.Record
  • conversion of binary JSON to Avro generated Java classes
  • conversion of binary Avro to binary JSON
  • optional field support (unions do not require wrapping)
  • unknown fields that are not declared in schema are ignored

Dependencies

dependencies {
    compile group: 'tech.allegro.schema.json2avro', name: 'converter', version: '0.2.10'
}

Basic usage

import tech.allegro.schema.json2avro.converter.AvroConversionException;
import tech.allegro.schema.json2avro.converter.JsonAvroConverter;
import org.apache.avro.generic.GenericData;
import org.apache.avro.Schema;

// Avro schema with one string field: username
String schema =
            "{" +
            "   \"type\" : \"record\"," +
            "   \"name\" : \"Acme\"," +
            "   \"fields\" : [{ \"name\" : \"username\", \"type\" : \"string\" }]" +
            "}";

String json = "{ \"username\": \"mike\" }";

JsonAvroConverter converter = new JsonAvroConverter();

// conversion to binary Avro
byte[] avro = converter.convertToAvro(json.getBytes(), schema);

// conversion to GenericData.Record
GenericData.Record record = converter.convertToGenericDataRecord(json.getBytes(), new Schema.Parser().parse(schema));

// conversion from binary Avro to JSON
byte[] binaryJson = converter.convertToJson(avro, schema);

// exception handling
String invalidJson = "{ \"username\": 8 }";    

try {
    converter.convertToAvro(invalidJson.getBytes(), schema);    
} catch (AvroConversionException ex) {
    System.err.println("Caught exception: " + ex.getMessage());
}

Validator

A command line tool for validating your JSON/Avro documents against a schema.

Build

To bundle the tool into single executable JAR:

./gradlew :validator:shadowJar
java -jar validator/build/libs/json2avro-validator-{version}.jar --help

Usage

Running Validator with --help option will print a help message listing all possible arguments. Sample Avro schema and messages can be found in:

  • schema: validator/src/test/resources/user.avcs
  • JSON message: validator/src/test/resources/user.json
  • Avro message: validator/src/test/resources/user.avro

JSON to Avro

You can validate your JSON to Avro conversion:

java -jar json2avro-validator.jar -s user.avcs -i user.json

If everything processes correctly, the process will end with zero status code.

Avro to JSON

You can convert the Avro binary data into JSON by setting mode -m avro2json option:

java -jar json2avro-validator.jar -s user.avcs -i user.avro -m avro2json

JSON to Avro to JSON

If you would like to know how messages will look like after encoding and decoding invoke:

java -jar json2avro-validator.jar -s user.avcs -i user.json -m json2avro2json

License

json-avro-converter is published under Apache License 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].