Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASN.1 vs JSON when is is appropriate to use them?

When is using ASN.1 preferable to using JSON? What are some advantages and disadvantages of both approaches?

like image 716
Eric des Courtis Avatar asked Jun 29 '12 13:06

Eric des Courtis


People also ask

Why use ASN 1?

Because ASN. 1 is both human-readable and machine-readable, an ASN. 1 compiler can compile modules into libraries of code, codecs, that decode or encode the data structures.

What is an ASN 1 file?

ASN. 1, or Abstract Syntax Notation One, is an International Standards Organization (ISO) data representation format used to achieve interoperability between platforms. NCBI uses ASN. 1 for the storage and retrieval of data such as nucleotide and protein sequences, structures, genomes, PubMed records, and more.


2 Answers

ASN.1 and JSON aren't strictly comparable. JSON is a data format. ASN.1 is a schema language plus multiple sets of encoding rules, each of which produces different data formats for a given schema. So, the original question somewhat parallels the question "XML Schema vs. XML: when is it appropriate to use them?" A fairer comparison would be between ASN.1 and JSON Schema.

That said, a few points to consider:

  • ASN.1 has binary encoding rules. Consider whether binary or text encoding is preferable for your application.
  • ASN.1 also has XML and JSON encoding rules. You can opt to go with a text-based encoding using ASN.1, if you like.
  • ASN.1 allows other encoding rules to be developed. Before ITU-T specified encoding rules for JSON, we specified our own rules to encode ASN.1 to JSON. I blogged about this on our company website here
  • As with XML Schema, tools exist for compiling ASN.1. These are commonly referred to as data binding tools. The compiler output consists of data structures to hold your data, and code for encoding/decoding to/from the various encodings (binary, XML, JSON).
  • I am not sure what, if any, data binding tools exist for JSON Schema. I am also not sure how mature/stable JSON Schema is, whereas ASN.1 is quite mature and stable.
  • Choosing between JSON Schema and ASN.1, note that JSON Schema is bound to JSON, whereas ASN.1 is not bound to any particular representation.
like image 107
Kevin Avatar answered Sep 20 '22 02:09

Kevin


You can use ASN.1 regardless of whether you need to serialize messages that might go to a recipient using C, C++, C#, Java, or any other programming language with ASN.1 encoder/decoder engine. ASN.1 also provides multiple encoding rules which have benefits under different circumstances. For example, DER is used when a canonical encoding is crucial, such as in digital certificates, while PER is used when bandwidth is critical such as in cellular protocols, and E-XER is used when you don't care about bandwidth and would like to display an encoding in XML for maniplulation in a browser or exchange messages with an XML Schema engine.

Note that with a good ASN.1 tool, you don't have to change you application code to switch between these ASN.1 encoding rules. A simple function call can select the encoding rules you would like to use.

like image 43
Paul Thorpe Avatar answered Sep 19 '22 02:09

Paul Thorpe