JSON2ASN — Help

This web app allows you to generate an ASN.1 schema for your JSON messages. With an ASN.1 schema you can serialize and validate your messages in a variety of formats - binary (DER, PER, OER, etc) and text (XML and JSON).

JSON2ASN is a web tool that allows you to create a ASN.1 schema from a JSON message. Using the generated ASN.1 schema, you can then automatically generate code to serialize and parse your data in a variety of formats, and validate any message for conformance with the schema.

There are two scenarios in which this tool may be helpful.

  • When your protocol matures, you will need a schema for it. This tool allows a quick way to develop a schema using your sample messages.
  • If you know JSON better than you know ASN.1, you may describe your data in JSON, then convert this JSON into ASN.1 schema.

ASN.1 is a proven standard that's been developed since 1980s, and has been already used in serializing and parsing many types of messages, from the simplest to the most complex (TODO quote 3GPP and other important standards that use ASN.1)

While ASN.1 offers many features, this web tool uses a small subset of them to simplify writing and understanding of the schemas. Below you can see an example of a JSON message with its generated ASN.1 schema.

{
 "name":"Adam",
 "first-words":"Hello World",
 "age":{
  "biblical":930
 }
}

SEQUENCE {
 name UTF8String,
 first-words UTF8String,
 age SEQUENCE {
  biblical INTEGER
 }
}

Once you generate your ASN.1 schema, you can:

  • edit it to add new fields, remove unneeded fields or modify existing ones.
  • use any ASN.1 compiler to generate the model and parsing/serializing code, and use a variety of formats to create and read messages, either text-based (JSON) or binary (DER, OER, PER, etc)
  • use a tool (TODO like DCODEC) to directly validate JSON messages against your schema
Lists
[
 {"id":1, "name":"File"},
 {"id":2, "name":"Edit"},
 { "name":""}
]

SEQUENCE OF SEQUENCE {
 name UTF8String,
 id INTEGER OPTIONAL
}


Collection of related objects
{
"shapes" :  [
  {"area":3.14,"radius":1},
  {"area":1,"x":1,"y":1},
  {"area":2,"b":1,"h":2},
 ]
}


shapes SEQUENCE OF SEQUENCE {
 area INTEGER,
 y INTEGER OPTIONAL,
 x INTEGER OPTIONAL,
 radius INTEGER OPTIONAL,
 h INTEGER OPTIONAL,
 b INTEGER OPTIONAL
}

Tuples
{
"location" :  [
  “New York”,
  8550405,
  790,
  {"x":-74.96778,"y":49.6743}
 ]
}

location [ARRAY] SEQUENCE {
 item0 UTF8String,
 item1 INTEGER,
 item2 INTEGER,
 item3 SEQUENCE {
  y REAL,
  x REAL }
}

Collection of various objects in random order
{
"everything" :  [
  {
   "model":"Toyota",
   "passengers":5,
   "auto":true
  },
  {
   "brand":"Absolut",
   "proof":80
  },
  {
   "material":"wood",
   "country":"USA",
   "year":2017
  }
 ]
}

everything SEQUENCE OF [JER: UNWRAPPED] CHOICE {
 alternative0 SEQUENCE {
  passengers INTEGER,
  model UTF8String,
  auto BOOLEAN
 },
 alternative1 SEQUENCE {
  proof INTEGER,
  brand UTF8String
 },
 alternative2 SEQUENCE {
  year INTEGER,
  material UTF8String,
  country UTF8String
 }
}



You can include in the JSON message several array elements with either all the fields or with some fields missing. If you select the "List of similar items" option in the Arrays section, the JSON2ASN tool will try to find the minimum schema that will fit all the elements using OPTIONAL fields, as can be seen in the example below:

[
 {
  "name":"Adam"
 },
 {
  "name":"Adam",
  "first-words":"Hello World"
 },
 {
  "age":{
   "biblical":930
  }
 }
]

SEQUENCE OF SEQUENCE {
 age SEQUENCE {
  biblical INTEGER
 } OPTIONAL,
 name UTF8String OPTIONAL,
 first-words UTF8String OPTIONAL
}








If you have an array of different elements, you can choose the "An unordered collection of various items" option in the Arrays section to generate a schema that allows for such elements, as you can see in the example below:

{
"everything": {
 [
  {
   "model":"Toyota",
   "passengers":5,
   "auto":true
  },
  {
   "brand":"Absolut",
   "proof":80
  },
  {
   "material":"wood",
   "country":"USA",
   "year":2017
  }
 ]
}

everything SEQUENCE OF [JER: UNWRAPPED] CHOICE {
 alternative0 SEQUENCE {
   model UTF8String,
   passengers INTEGER,
   auto BOOLEAN
 },
 alternative1 SEQUENCE {
   brand UTF8String,
   proof INTEGER
 },
 alternative2 SEQUENCE {
   material UTF8String,
   country UTF8String,
   year
 }
}




*Note: to generate an exact schema, Encoding Instructions are needed. To obtain this, please also check the "Allow ASN.1 Encoding Instructions" option in the Other section.
For more information on Encoding Instructions, please read the section regarding Encoding Instructions below.

In order for your schema to support adding new fields in future versions of it, the JSON2ASN has the option to create extensible objects that enable you to add new fields to them, and still be able to correctly decode the messages with older versions. To do this, you can check the "Make objects extensible" option in the Other section. The generated schema will contain the extensible marker ("...") for each SEQUENCE and CHOICE.
Also consider marking schema fields as OPTIONAL, so they can be deprecated with new schema versions.

You can see how this works in the example below:

[
 {
  "name":"Adam"
 },
 {
  "name":"Adam",
  "first-words":"Hello World"
 },
 {
  "age":{
   "biblical":930
  }
 }
]



SEQUENCE OF [JER: UNWRAPPED] CHOICE {
 alternative0 SEQUENCE {
  name UTF8String
 },
 alternative1 SEQUENCE {
  name UTF8String,
  first-words UTF8String
 },
 alternative2 SEQUENCE {
  age SEQUENCE {
   biblical INTEGER,
   ...
  }
 }
 ,...
}

Yes you can. It's as simple as putting them together in an array before passing to the json2asn tool (e.g. [{"message":..... }, {"message":.....}, ........]), and JSON2ASN will generate a schema that will support all the messages.

ASN.1 schemas not only define data structures, but may also govern data encoding (serialization) details. Encoding Instructions specifying such details.

For more information on Encoding Instructions, please read http://www.oss.com/asn1/resources/asn1-papers/Overview%20of%20JER.pdf

  • To apply various schema generation options to various parts of a message split it into multiple objects and get several schemas , then re-combine schemas into one
  • Provide default values, it will allow more compact encodings
  • In an array do not use null to skip objects, use {} instead. ASN.1 arrays (SEQUENCE OF) have no notion of a null element