📜 ⬆️ ⬇️

What is AXON

AXON is a notation for the serialized representation of objects, documents, and data in textual form. It combines the simplicity of JSON , the extensibility of XML and the readability of YAML .


There is a pyaxon project in python that you can play with. However, it was created in such a way that it is not much inferior in speed with the json module. Therefore, it can be useful for real cases.


Why AXON?


AXON appeared as an attempt to cope with the disadvantages or inconveniences of JSON and XML , but at the same time to preserve their strengths and capabilities, adding the readability inherent in YAML .



AXON contains an "improved" version of JSON


1. JSON has two disadvantages:



AXON eliminates these inconveniences as follows:



The result is a more compact representation and ease of perception when formatting.


For comparison:


JSON


 { "name": "Alex", "birth": "1979-12-25", "email": "mail@example.com"} [ "Alex" "1979-12-25" "mail@example.com"] 

AXON


 { name: "Alex" birth: ^1979-12-25 email: "mail@example.com"} [ "Alex" ^1979-12-25 "mail@example.com"] 

2. In JSON not guaranteed that after loading


 { "name": "Alex", "birth": "1979-12-25", "email": "mail@example.com"} 

The order of the keys / attributes is preserved.


The AXON states that


 { name: "Alex" birth: ^1979-12-25 email: "mail@example.com"} 

converted to mapping without saving the order of the keys.


At the same time, it is stated that


 [ name: "Alex" birth: ^1979-12-25 email: "mail@example.com"] 

converted to mapping preserving the order of the keys.


3. AXON supports syntax to represent date and time in an ISO format:



 ^2010-12-31 


 ^12:30 ^12:30:15 ^12:30+03:00 ^12:30:15-04:30 


 ^2010-12-31T12:30 ^2010-12-31T12:30:05.0125 ^2010-12-31T12:30+04:00 ^2010-12-31T12:30:05.0123-04:00 

and also to represent decimal numbers:


 1D 123456789D 3.14D 1.23e-6D 

4. AXON also allows you to define labels of non-atomic values ​​and use them as internal links . This allows, if necessary, not to create copies of reusable non-atomic values ​​during serialization / deserialization.


For example:


 [ { prev: &a (2012-12-30 10:00) next: &c (2012-01-01 12:00) } { prev: &b (2012-12-31 13:00) next: *a } { prev: *c next: *b } ] 

The label has the prefix & ( &a &b &c ), and the link has the prefix * ( *a *b *c ).


The AXON data model contains a variant of the Infoset XML model in a more compact notation.


Consider an illustrative example of an XML representation of structured data:


 <person> <name>John Smith</name> <age>25</age> <address type="home"> <street>21 2nd Street</street> <city>New York</city> <state>NY</state> </address> <phone type="home">212-555-1234</phone> </person> 

AXON implements the idea of ​​simpler syntax for representing XML structured data:


 person { name {"John Smith"} age {25} address { type: "home" street {"21 2nd Street"} city {"New York"} state {"NY"} } phone {type:"home" "212-555-1234"} } 

The representation in AXON format can be built from XML in 5 steps:


  1. Replace <tag> with tag {
  2. Replace </tag> with }
  3. Replace attr=value with attr: value
  4. Text inside elements must be enclosed in double quotes ( " )
  5. Delete the character with a comma ( , ) or replace it with a single space

The result of this transformation is structurally identical to the original XML document. Essentially this is a syntactically more compact form of representing an XML document.


For comparison, we also present the representation in AXON with the formatting of complex elements without {} using the principle of the same indentation for the sub-elements of the structure:


 person name {"John Smith"} age {25} address type: "home" street {"21 2nd Street"} city {"New York"} state {"NY"} phone type: "home" "212-555-1234" 

This view is obtained from the previous one by deleting all {and} characters, as well as unnecessary blank lines.


AXON extends XML and JSON


In XML attributes can only have simple values, in AXON , an attribute value can have any value (as in JSON ). In addition, simple values ​​are of type ( text in unicode format, number , decimal number , date and time , byte array in base64 encoding). AXON can be thought of as an extension of JSON in the sense that objects can be named, as well as XML elements are named.


For example:


 person name: "John Smith" age: 25 burn: 1975-10-21 locations: [ address type: "home" street: "21 2nd Street" city: "New York" state: "NY" ] contacts: [ phone type: "home" "212-555-1234" email type: "personal" "mail@example.com" ] 

In JSON there is one disadvantage associated with the representation of irregular structures in which the order of the parts is significant. In such structures, access to elements occurs as a result of a sequential search by name, and not as a result of "direct" access by name.


As an example, consider a structured XML document:


 <section title="Title"> <par style="normal">paragraph</par> <enumerate style="enum"> <item>item text</item> </enumerate> <par style="normal">paragraph</par> <itemize style="itemize"> <item>item text</item> </itemize> <par style="normal">paragraph</par> </section> 

Directly, without a structure transformation, this document is not translated into JSON due to the importance of the order and repeatability of the elements. One translation variant that emulates a sequence of named elements is:


 { "tag": "section", "@": {"title": "Title"}, "*": [ { "tag": "par", "@": {"style":"normal", "text":"paragraph"}}, { "tag":"enumerate", "@": {"style": "enumerate"}, "*": [ { "tag":"item", "@": {"text":"item text"}} ] }, { "tag": "par", "@": {"style":"normal", "text":"paragraph"}}, { "tag":"itemize", "*": [ { "tag":"item", "@": {"text":"item text"}} ] }, { "tag": "par", "@": {"style":"normal", "text":"paragraph"}} ] } 

In AXON such structures are translated "one to one":


 section title: "Title" par style: "normal" "paragraph" enumerate style: "enum" item { "item text" } par style: "normal" "paragraph" itemize style: "itemize" item { "Item text" } par style: "normal" "paragraph" 

AXON supports YAML style formatting.


The attractive side of YAML is the wiki presentation format. AXON also supports a similar formatting style.
For example, for comparison:



 person name: "Alex" age: 25 


 person { name: "Alex" age: 25} 


 person{name:"Alex" age:25} 

AXON can represent a series of objects.


One of the limitations of JSON and XML is that they represent a single root object. In contrast, AXON represents a series of objects or a series of : pairs that can be loaded one by one. For example:



 { name: "Alex" age: 32 } { name: "Michael" age: 28 } { name: "Nick" age: 19 } 


 alex: { message: "Hello" datetime: ^2015-07-12T12:32:35 } michael: { message: "How are you" datetime: ^2015-07-12T12:32:35 } 

')

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


All Articles