ASN.1 vs JSON, when is it appropriate to use?

When is ASN.1 used? Is it preferable to use JSON? What are some of the advantages and disadvantages of both approaches?

+6
source share
2 answers

ASN.1 and JSON are not strictly comparable. JSON is a data format. ASN.1 is a schema language and many sets of coding rules, each of which creates different data formats for a given schema. So, the original question is somewhat parallel to the question "XML Schema vs. XML: when is it appropriate to use?" A fairer comparison would be between ASN.1 and JSON Schema.

However, a few considerations:

  • ASN.1 has binary encoding rules. Consider whether binary or text encoding is preferred for your application.
  • ASN.1 also has XML encoding rules. If you wish, you can select a text based encoding using ASN.1.
  • ASN.1 allows the development of other coding rules. In fact, we specified our own (non-standardized) rules for encoding ASN.1 in JSON. I wrote about it on our company website here
  • As in the XML schema, there are tools for compiling ASN.1. These are commonly called data binding tools. The compiler output consists of data structures for storing your data and code for encoding / decoding to / from various encodings (binary, XML or, if our JSON tool is used).
  • I'm not sure if there are data binding tools for the JSON schema, if any. I'm also not sure how mature / stable JSON Schema is, whereas ASN.1 is pretty mature and stable.
  • When choosing between JSON Schema and ASN.1, note that JSON Schema is bound to JSON, while ASN.1 is not bound to any particular view.
+15
source

You can use ASN.1 regardless of whether you need to serialize messages that can be sent to the recipient using C, C ++, C #, Java or any other programming language using the ASN.1 encoding / decoding mechanism. ASN.1 also provides several encoding rules that are advantageous in a variety of circumstances. For example, DER is used when canonical encoding is critical, for example, in digital certificates, while PER is used when bandwidth is critical, for example, in cellular protocols, and E-XER is used when you don't need bandwidth and you want to display encoding in XML for maniplulation in a browser or messaging with the XML Schema engine.

Please note that with a good ASN.1 tool you do not need to change the application code to switch between these ASN.1 encoding rules. A simple function call can choose the encoding rules that you would like to use.

+2
source

Source: https://habr.com/ru/post/919326/


All Articles