Home

Awesome

Overview

exificient-for-json is an implementation of the EXI4JSON specification (see https://www.w3.org/TR/exi-for-json/) in Java. EXI4JSON converts JSON to event streams which result in a very processing efficient and compact format. Lossless round-trip conversion back to the original JSON structures is supported. EXI4JSON is based on EXI and uses its built-in datatypes.

The project uses MIT license.

Build Status

Background

Due to its EXI/XML nature EXI4JSON can be serialized/visualized as XML. Most of the use-case do not need this features but in some situation it may turn out very hand.

A JSON example

{
  "keyNumber": 123,
  "keyArrayStrings": [
    "s1",
    "s2"
  ]
}

can be transformed to

<j:map xmlns:j="http://www.w3.org/2015/EXI/json">
  <j:keyNumber>
    <j:number>123</j:number>
  </j:keyNumber>
  <j:keyArrayStrings>
    <j:array>
      <j:string>s1</j:string>
      <j:string>s2</j:string>
    </j:array>
  </j:keyArrayStrings>
</j:map>

How to get it

Released with Maven

<dependency>
    <groupId>com.siemens.ct.exi</groupId>
    <artifactId>exificient-for-json</artifactId>
    <version>1.0.0</version>
</dependency>

or also as snapshot.

<dependency>
    <groupId>com.siemens.ct.exi</groupId>
    <artifactId>exificient-for-json</artifactId>
    <version>1.0.1-SNAPSHOT</version>
</dependency>

How to use the library

Java API for JSON Processing

// generate by simply providing input and output
EXIforJSONGenerator e4jGenerator = new EXIforJSONGenerator();
e4jGenerator.generate(isJSON, osEXI4JSON);
// Note: one can also fire events like writeStartObject(),  writeKeyName(key) etc

// parse by simply providing input and output again
EXIforJSONParser e4jParser = new EXIforJSONParser();
e4jParser.parse(isEXI4JSON, osJSON);
// Note: one can again read events by readNextEvent(), getKeyName(),  getValueString() etc

Jackson

EXI4JSONFactory fEXI = new EXI4JSONFactory();
ObjectMapper mapperEXI = new ObjectMapper(fEXI);
ObjectMapper mapperJSON = new ObjectMapper();

String carJson =
    "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }";
JsonNode car = mapperJSON.readTree(carJson); 

// generate
OutputStream e4jOS = ...; // output stream
mapperEXI.writeTree(fEXI.createGenerator(e4jOS), car);
// parse
OutputStream e4jIS = ...; // input stream
EXI4JSONParser eparser = fEXI.createParser(e4jIS);
JsonNode carAgain = mapperJSON.readTree(eparser);

Compression Results

See test-data in https://github.com/EXIficient/exificient-for-json/tree/master/src/test/resources.

TestCaseJSON [Size in Bytes]CBOR [Size in Bytes]Smile [Size in Bytes]EXI4JSON [Size in Bytes]
glossary.json605311309322
gpx\sample-set-1\gpx-1-100pts.json11007737865926210
gpx\sample-set-1\gpx-1-10pts.json1318898832778
gpx\sample-set-1\gpx-1-1pts.json314248254223
gpx\sample-set-1\gpx-1-200pts.json21661145781299212179
gpx\sample-set-1\gpx-1-20pts.json2424161814721395
gpx\sample-set-1\gpx-1-2pts.json426322320284
gpx\sample-set-1\gpx-1-300pts.json32452217781939218216
gpx\sample-set-1\gpx-1-30pts.json3480233821121984
gpx\sample-set-1\gpx-1-3pts.json537394384346
gpx\sample-set-1\gpx-1-400pts.json43257289782579224239
gpx\sample-set-1\gpx-1-40pts.json4562305827522588
gpx\sample-set-1\gpx-1-4pts.json648466448408
gpx\sample-set-1\gpx-1-500pts.json53988361783219230256
gpx\sample-set-1\gpx-1-50pts.json5634377833923191
gpx\sample-set-1\gpx-1-5pts.json760538512469
gpx\sample-set-1\gpx-1-600pts.json64758433783859236284
gpx\sample-set-1\gpx-1-60pts.json6720449840323801
gpx\sample-set-1\gpx-1-6pts.json872610576531
gpx\sample-set-1\gpx-1-700pts.json75518505784499242285
gpx\sample-set-1\gpx-1-70pts.json7778521846724396
gpx\sample-set-1\gpx-1-7pts.json983682640593
gpx\sample-set-1\gpx-1-800pts.json86292577785139248293
gpx\sample-set-1\gpx-1-80pts.json8859593853125000
gpx\sample-set-1\gpx-1-870pts.json93786628185587252476
gpx\sample-set-1\gpx-1-8pts.json1094754704655
gpx\sample-set-1\gpx-1-90pts.json9942665859525609
gpx\sample-set-1\gpx-1-9pts.json1206826768716
json-generator.com\2015-01-06\01.json1103353490133351756310012
json-generator.com\2015-01-06\02.json2203693979469703115606056
json-generator.com\2015-01-06\03.json323805614383701032056881484
json-generator.com\2015-01-06\04.json4320187191877113766201168143
json-generator.com\2015-01-06\05.json5425885240984917289131461451
json-generator.com\2015-01-06\06.json6509681289082820736701749445
json-generator.com\2015-01-06\07.json7620054338375524271812044025
json-generator.com\2015-01-06\08.json8880856394358828286692379084
json-generator.com\2015-01-06\09.json9982416443301331798082672229
json-generator.com\2015-01-06\10.json11080993492062635293842965358
openweathermap.org\sample-set-1\owm-1-1000cities.json622540514167311697223442
openweathermap.org\sample-set-1\owm-1-100cities.json62024510743087723032
openweathermap.org\sample-set-1\owm-1-10cities.json6170506932052629
openweathermap.org\sample-set-1\owm-1-1cities.json615502464486
openweathermap.org\sample-set-1\owm-1-200cities.json1238111018576127244954
openweathermap.org\sample-set-1\owm-1-2cities.json12311011773726
openweathermap.org\sample-set-1\owm-1-300cities.json1856991527879185567573
openweathermap.org\sample-set-1\owm-1-400cities.json24771820387712264090258
openweathermap.org\sample-set-1\owm-1-500cities.json309532254791153303112848
openweathermap.org\sample-set-1\owm-1-50cities.json31048255571553411820
openweathermap.org\sample-set-1\owm-1-5cities.json3136258717281535
openweathermap.org\sample-set-1\owm-1-600cities.json371839306314184489133633
openweathermap.org\sample-set-1\owm-1-700cities.json433746357313215231156390
openweathermap.org\sample-set-1\owm-1-800cities.json498084411365249407179022
openweathermap.org\sample-set-1\owm-1-900cities.json560315462826280620201229

On average "EXI4JSON" is about 48% of the original JSON filesize! On average "EXI4JSON" is about 50% smaller than the CBOR binary encoded file!

Compression Figure