Internet Engineering Task Force P. THOMY Internet-Draft Loco-labs Intended status: Informational September 2023 Expires: 7 March 2024 JSON semantic format (JSON-NTV) draft-thomy-json-ntv-01 Abstract This document describes a set of simple rules for unambiguously and concisely encoding semantic data into JSON Data Interchange Format. These rules are based on an NTV (Named and Typed Values) data structure applicable to any simple or complex data. The JSON-NTV format is its JSON translation. Status of This Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at https://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on 4 March 2024. Copyright Notice Copyright (c) 2023 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/ license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License. THOMY Expires 7 March 2024 [Page 1] Internet-Draft JSON semantic format (JSON-NTV) September 2023 Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1. Presentation . . . . . . . . . . . . . . . . . . . . . . 3 1.2. Key design features . . . . . . . . . . . . . . . . . . . 4 1.3. Requirements Language . . . . . . . . . . . . . . . . . . 5 2. NTV structure . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1. NTV layers . . . . . . . . . . . . . . . . . . . . . . . 6 2.2. NTV entities . . . . . . . . . . . . . . . . . . . . . . 6 2.2.1. NTVsingle . . . . . . . . . . . . . . . . . . . . . . 7 2.2.2. NTVlist . . . . . . . . . . . . . . . . . . . . . . . 7 2.3. NTVtype and Namespace . . . . . . . . . . . . . . . . . . 8 2.3.1. Namespace . . . . . . . . . . . . . . . . . . . . . . 8 2.3.2. NTVtype . . . . . . . . . . . . . . . . . . . . . . . 8 2.3.3. Representation . . . . . . . . . . . . . . . . . . . 9 3. JsonNTV . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.1. JsonNTV format . . . . . . . . . . . . . . . . . . . . . 11 3.2. JsonNTVname . . . . . . . . . . . . . . . . . . . . . . . 12 3.3. JsonNTVtype . . . . . . . . . . . . . . . . . . . . . . . 13 3.4. JsonNTVvalue . . . . . . . . . . . . . . . . . . . . . . 14 4. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5. Parsing a JsonValue . . . . . . . . . . . . . . . . . . . . . 16 5.1. JSON decoding . . . . . . . . . . . . . . . . . . . . . . 17 5.2. NTV entity decoding . . . . . . . . . . . . . . . . . . . 17 5.3. NTVvalue decoding . . . . . . . . . . . . . . . . . . . . 18 5.4. NTVtype decoding . . . . . . . . . . . . . . . . . . . . 18 6. NTV extended structure . . . . . . . . . . . . . . . . . . . 19 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 19 8. Security Considerations . . . . . . . . . . . . . . . . . . . 19 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 19 9.1. Normative References . . . . . . . . . . . . . . . . . . 19 9.2. Informative References . . . . . . . . . . . . . . . . . 20 Appendix A. Global NTVtype and Namespace . . . . . . . . . . . . 21 A.1. Json . . . . . . . . . . . . . . . . . . . . . . . . . . 21 A.2. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 21 A.3. Datation . . . . . . . . . . . . . . . . . . . . . . . . 22 A.4. Period and Duration . . . . . . . . . . . . . . . . . . . 24 A.5. Location . . . . . . . . . . . . . . . . . . . . . . . . 24 A.6. Structured data . . . . . . . . . . . . . . . . . . . . . 26 A.7. Normalized String . . . . . . . . . . . . . . . . . . . . 26 A.8. Namespace . . . . . . . . . . . . . . . . . . . . . . . . 27 A.9. Custom NTVtype and Namespace . . . . . . . . . . . . . . 27 Appendix B. Complete ABNF notation . . . . . . . . . . . . . . . 28 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 30 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 30 THOMY Expires 7 March 2024 [Page 2] Internet-Draft JSON semantic format (JSON-NTV) September 2023 1. Introduction 1.1. Presentation The semantic level of JSON or CSV shared data remains low. It is often limited to the type of data defined in those exchange formats (strings for CSV formats; numbers, strings, arrays and objects for JSON formats). JSON-NTV proposes to increase the semantic level of the JSON entities [RFC8259] by adding two additional pieces of information to a JSON entity : * *name*: interpretation of the JSON value in human language or detailed information or link to external information, * *type*: interpretation of the JSON value in a data standard (eg. GeoJSON, datetime), in a data catalog or in a software language. The NTV entity is thus a triplet with a mandatory element (value) and two additional elements (name, type). _For example, Paris location can be represented by :_ - _a name : "paris",_ - _a type : geoJSON Point coordinates [RFC7946],_ - _a value : [2.3522, 48.8566]_ The easiest way to add that information into a JSON value is to use a JSON object with a single member. The first term is the additional elements using the syntax JSON-ND [JSON-ND]. The second term is the JSON value. _The JSON value of the previous example is:_ _{ "paris:point" : [2.3522, 48.8566] }_ With this approach, two NTV entities are defined : * *a primitive entity* which is not composed of any other entity, * *a structured entity* which is an ordered sequence of NTV entities. as well as two JSON formats depending on the presence of the additional elements : * *simple format* when name and type are not present THOMY Expires 7 March 2024 [Page 3] Internet-Draft JSON semantic format (JSON-NTV) September 2023 * *named format* when name or type is present _Example (entity composed of two other primitive entities):_ _{ "cities::point": [[2.3522, 48.8566], [4.8357, 45.7640]] } simple format for primitive entities_ _{"cities::point": {"paris":[2.3522, 48.8566], "lyon":[4.8357, 45.7640]}} named format for primitive entities_ A JSON-NTV generator produces a JSON value from a NTV entity and vice versa a JSON-NTV parser transforms a JSON value into a NTV entity. The conversion between NTV entity and native entity is outside the scope of this note. 1.2. Key design features The format is focused on simplicity, lightness and web usage. The key features of this format are the following: * *JSON as the base format* - JSON is simple and readable as simple text - JSON supports rich structure including nesting and basic types - JSON is web-native and very widely used and supported - JSON format has binary representation (eg. CBOR format) * *high semantic level of data* - wide variety of data typing - tree-like and customisable data typing * *compatibility with existing formats* - All JSON data is a JsonNTV data - All NTVtypes are standard types * *compatibility with any type of platform* - types and structures are independent of software and hardware platforms THOMY Expires 7 March 2024 [Page 4] Internet-Draft JSON semantic format (JSON-NTV) September 2023 - the NTV concept is applicable to all types of "jsonable" data * *reversibility* - the NTV entity coming from a JSON value is identical to the NTV entity from which the JSON value comes - the JSON representation of an NTV entity is the same as the JSON value used to construct the NTV entity * *tree structure* - all NTV entities are trees - tree properties are applicable to NTV entities 1.3. Requirements Language The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here. This document also uses the following terms: *JsonType, JsonText, JsonName, JsonValue, JsonObject, JsonMember, JsonElement, JsonArray, JsonNumber, JsonString, JsonFalse, JsonNull, JsonTrue:* These terms are defined as type, text, name, value, object, member, element, array, number, string, false, null, true in the JSON grammar. *JsonPrimitive:* A JsonNumber, JsonString, JsonFalse, JsonTrue or JsonNull. *JsonUnnamed:* A JsonObject without a single member. *JsonNamed:* A JsonObject with a single member. *NTVsingle, NTVlist:* NTVlist and NTVsingle entities can be abbreviated as: * NVsingle : entity with default NTVtype "json", * NVlist : entity without NTVtype, THOMY Expires 7 March 2024 [Page 5] Internet-Draft JSON semantic format (JSON-NTV) September 2023 * TVsingle, TVlist : entity without NTVname, * Vsingle, Vlist : NVsingle or NVlist without NTVname. 2. NTV structure 2.1. NTV layers NTV and JsonNTV structures are defined as shown in Figure 1: * NTV is a data triplet (NTVname, NTVtype, NTVvalue) that contains all the information needed to build the native entity. * JsonNTV is the JsonValue of the NTV entity. JsonNTV is used to build an interchangeable JsonText +--------+ JSON load +-------+ NTV load +-------+ to_obj +------+ | |---------->| |--------->| NTV |--------->|native| |JsonText| |JsonNTV| |triplet| |entity| | |<----------| |<---------| |<---------| | +--------+ JSON dump +-------+ NTV dump +-------+ from_obj +------+ Figure 1: NTV layers _Example:_ * _Native layer_ new_year_2022 = datetime.date(2022, 01, 01) _is a Python variable "new_year_2022" corresponding to a datetime object_ * _NTV layer_ ("new_year_2022", "date", "2022-01-01") _is a triplet_ * _JsonNTV layer_ { "new_year_2022:date" : "2022-01-01" } _is a JsonValue_ * _JsonText layer_ '{"new_year_2022:date":"2022-01-01"}' _is a JsonString_ 2.2. NTV entities Two categories of entities (one primitive and one structured) are defined: THOMY Expires 7 March 2024 [Page 6] Internet-Draft JSON semantic format (JSON-NTV) September 2023 * *NTVsingle* for the primitive entity, * *NTVlist* for an ordered sequence of NTV entities An NTV entity is therefore a tree where the leaves nodes are the NTVsingle entities and where the inner nodes are the NTVlist entities 2.2.1. NTVsingle The data triplet of NTVsingle entities is composed by: * *NTVsingleValue*: This NTVvalue is the JSON representation (JsonValue) of the main content of the NTV entity, * *NTVsingleType*: This NTVtype defines the type of entity and the conversion rules between the native entity and the NTV entity. The default NTVtype (defaultNTVtype) is the "json" NTVtype. * *NTVname*: The NTVname is an additional textual information (JsonString) *In other words, any entity that has on the one hand a function of encoding it into a JsonValue and on the other hand a function of creating from a JsonValue can be taken into account. This approach is very general because the majority of computer objects are defined by a list of parameters (e.g. *args in python) and/or a list of key/ values (e.g. **kwargs in python) which simply translate into a JsonArray or a JsonObject.* The consistency between NTVsingleValue and NTVsingleType is outside the scope of this note. 2.2.2. NTVlist The data triplet of NTVlist entities is composed by: * *NTVlistValue*: This NTVvalue is an ordered sequence of included NTV entities. * *NTVlistType*: This NTVtype is a Namespace or a NTVtype to apply to the NTV entities included. This NTVlistType avoids including a NTVtype (if NTVtype) or reduces the length (if Namespace) in the JSON representation (JsonNTV) of the included NTV entities. The default NTVtype (defaultNTVtype) is "None". * *NTVname*: The NTVname is an additional textual information (JsonString) THOMY Expires 7 March 2024 [Page 7] Internet-Draft JSON semantic format (JSON-NTV) September 2023 _Example of equivalent JSON representations:_ _where NTVlistType is None for the global NTVlist_ _[ { ":point" : [2.3522, 48.8566]}, {":point" : [4.8357, 45.7640]} ]_ _where NTVlistType is "point" for the global NTVlist_ _{ "::point" : [ [2.3522, 48.8566], [4.8357, 45.7640] ] }_ _If JSON-value is { "::dat" : ["2022-01-28T18-23-54", {":point": [1.1, 2.2] ] } }, the parsers deduce that the first NTVvalue has a "dat" NTVtype and the second a "point" NTVtype._ 2.3. NTVtype and Namespace NTVtype is defined in a nested structure called Namespace. This structuring of type makes it possible to reference any type of data that has a JSON representation and to consolidate all the shared data structures within the same tree of types. 2.3.1. Namespace A Namespace is defined by a name (NamespaceName) and a Namespace parent (NamespaceParent). The NamespaceName is unique in the NamespaceParent. Root node in the Namespace tree is the GlobalNamespace. REQ1: NamespaceParent of GlobalNamespace is None. 2.3.2. NTVtype A NTVtype is defined by a name (NTVtypeName) and a Namespace parent (NamespaceParent). The NTVtype is unique in the NamespaceParent. NTVtype and the rules to encode or decode NTVvalues MUST be understood by data producers and data consumers. So NTVtype and rules associated have to be defined in a specification shared by a large community. On the other hand, it must be possible for everyone to share data according to their own data structure. There are therefore two categories of NTVtype: * custom NTVtype (and Namespace) which can be created by anyone without control, THOMY Expires 7 March 2024 [Page 8] Internet-Draft JSON semantic format (JSON-NTV) September 2023 * shared NTVtype (and Namespace) that are defined in a single, shared repository. Each 'shared' Namespace or NTVtype is uniquely managed. For shared NTVtype, three sub-categories are defined (None, Simple, Generic). * The "None" NTVtype is used with NTVlist as defaultNTVtype. * Simple NTVtype is associated to conversion rules between a native entity and a NTV entity. * Generic NTVtype is equivalent to a set of Simple NTVtype. This indicates that parsers use associated simple NTVtype to decode the JsonNTVvalue. _Example:_ _"dat" is the generic NTVtypeName for "datetime" and "timeposix"_ _If a JSONvalue is { "::dat" : ["2022-01-28T18-23-54", 123456.78] }, the parser deduces that the first entity has a "datetime" NTVtypeName and the second a "timeposix" NTVtypeName._ 2.3.3. Representation A Namespace is defined by a string followed by a point (NamespaceName). A NTVtype is defined by a string (NTVtypeName). The representation of a Namespace (NamespaceLongName) is composed by all the nested NamespaceName. The representation of a NTVtype (NTVtypeLongName) is composed by the NamespaceLongName and the NTVtypeName. The NTVtypeLongName is defined in Figure 2, which uses ABNF from [RFC5234]. THOMY Expires 7 March 2024 [Page 9] Internet-Draft JSON semantic format (JSON-NTV) September 2023 ; representation of NtvType and Namespace (LongName) NTVtypeLongName = NamespaceParentLongName NTVtypeName NamespaceLongName = NamespaceParentLongName NamespaceName NamespaceParentLongName = NamespaceLongName NamespaceName = [ ["$"] JsonString "." ] ; REQ2 REQ3 NTVtypeName = ["$"] JsonString ; REQ3 Figure 2: JsonNTVtype - ABNF The corresponding rules are as follows: REQ2: NamespaceName and NamespaceLongName of GlobalNamespace are empty. REQ3: NTVtype (or Namespace) has 'custom' category if NTVtypeName (or NamespaceName) begins with '$' or NTVtypeParent has 'custom' category _Example for a representation of an NTVtype defined in two nested Namespace in the global Namespace:_ _"ns1.ns2.type"_ _where:_ _"ns1." is a NamespaceName of a Namespace defined in the global Namespace,_ _"ns2." is a NamespaceName of a Namespace defined in the "ns1" Namespace,_ _"type" is a NTVtypeName of a NTVtype defined in the "ns2" Namespace_ _Example of custom categories:_ _If "fr." is the name of a Namespace attached to the global Namespace and containing the Namespace 'BAN' and the NTVtype 'dep', then:_ - _"fr.dep" is a name of a shared NTVtype,_ - _"fr.$test" is a name of a custom NTVtype,_ - _"fr.$example.one" is a name of a custom NTVtype_ THOMY Expires 7 March 2024 [Page 10] Internet-Draft JSON semantic format (JSON-NTV) September 2023 - _"fr.BAN.$test" is a name of a custom NTVtype_ 3. JsonNTV 3.1. JsonNTV format The JsonNTV format is the JSON representation of an NTV entity (JsonValue) as defined in Figure 3, which uses ABNF from [RFC5234]. ; JSON representation of NTV entities (JsonNTV) JsonNTV = JsonNTVnamed / JsonNTVsimple ; REQ4 JsonNTVnamed = beginObject JsonNTVMember endObject JsonNTVsimple = JsonNTVvalue JsonNTVMember = JsonNTVname nSep JsonNTVvalue ; Extract of JSON grammar used in this document beginArray = ws "[" ws beginObject = ws "{" ws endArray = ws "]" ws endObject = ws "}" ws nSep = ws ":" ws vSep = ws "," ws ws = *( %x20 / %x09 / %x0A / %x0D ) JsonValue = JsonValue ; indicates that rule is defined in RFC8259 JsonString = JsonString ; indicates that rule is defined in RFC8259 Figure 3: JsonNTV - ABNF The JsonNTV format is built with the NTVname, NTVvalue and the JsonNTVtype. Two JsonNTV formats are defined: * named format (if NTVname or JsonType is not an empty string): _{ JsonNTVname : JsonNTVvalue }_ * simple format (if NTVname and JsonType are empty string): _JsonNTVvalue_ The corresponding rules are as follows: THOMY Expires 7 March 2024 [Page 11] Internet-Draft JSON semantic format (JSON-NTV) September 2023 REQ4: If JsonNTVname is empty, simple format is used This format allows full compatibility with existing JSON structures: * a JsonNumber, JsonString, JsonNull or JsonBoolean is the representation of a Vsingle entity, * a JsonObject with a single member is the representation of an NVsingle or TVsingle entity, * a JsonArray is the representation of a Vlist entity, * a JsonObject without a single member is the representation of a Vlist entity composed with unnamed entities. _Note :_ * _JsonNTV : 21, { ":" : 21 } and { ":json" : 21 } represent the same Vsingle entity,_ 3.2. JsonNTVname JsonNTVname is the concatenation of NTVname and JsonSepType. JsonSepType is composed with the separator singleSep or listSep and the JsonNTVtype. JsonNTVname and JsonSepType are defined in Figure 4, which uses ABNF from [RFC5234]. ; JSON representation of NTVname and NTVtype (JsonNTVname) JsonNTVname = NTVname JsonSepType JsonSepType = [singleSep [JsonNTVtype]]/[listSep JsonNTVtype] ; REQ5 REQ6 NTVname = JsonString singleSep = ":" ; NTVsingle separator listSep = "::" ; NTVlist separator Figure 4: JsonNTVname - ABNF For NTVsingle entities: REQ5: If JsonNTVtype is not "json", JsonSepType is identical to singleSep joined with JsonNTVtype, THOMY Expires 7 March 2024 [Page 12] Internet-Draft JSON semantic format (JSON-NTV) September 2023 else if JsonNTVvalue is not a JsonArray and not a JsonUnnamed, JsonSepType is empty, else JsonSepType is identical to singleSep. For NTVlist entities: REQ6: If JsonNTVtype is not empty, JsonSepType is identical to listSep joined with JsonNTVtype else JsonSepType is empty. 3.3. JsonNTVtype The JSON representation of a NTVtype (JsonNTVtype) is a compact representation of the NTVtype in the context of the NTVtypeParent. The JsonNTVtype is defined in Figure 5, which uses ABNF from [RFC5234]. ; JSON representation of NtvType (JsonNTVtype) JsonNTVtype = [ NTVtypeLongName / relativeNTVtypeLongName ] ; REQ7 relativeNTVtypeLongName = *NamespaceName NTVtypeName ; REQ7 Figure 5: JsonNTVtype - ABNF The corresponding rules are as follows: REQ7: if NTVtype is identical to NTVtypeParent, JsonNTVtype is empty, else if NTVtypeParent is a Namespace and if NTVtype is including in NTVtypeParent, JsonNTVtype is the NTVtypeLongName relative to the NTVtypeParent. else JsonNTVtype is the NTVtypeLongName _Example:_ _If "fr." is the name of a Namespace attached to the global Namespace and containing the NTVtype 'dep', then:_ - _{ "::fr." : { "department1:dep": "name1", "department2:dep": "name2" } } is a valid JsonNTV representation._ THOMY Expires 7 March 2024 [Page 13] Internet-Draft JSON semantic format (JSON-NTV) September 2023 3.4. JsonNTVvalue The JsonNTVvalue is the JsonValue representation of NTVvalue as defined in Figure 6, which uses ABNF from [RFC5234]. ; JSON representation of NTVvalue (JsonNTVvalue) JsonNTVvalue = JsonNTVsingleValue / JsonNTVlistValue JsonNTVsingleValue = NTVsingleValue JsonNTVlistValue = JsonNTVarrayValue / JsonNTVobjectValue ; REQ8 JsonNTVarrayValue = beginArray ListJsonNTVvalue endArray ListJsonNTVvalue = [JsonNTV *( vSep JsonNTV )] JsonNTVobjectValue = beginObject ListJsonNTVmember endObject ListJsonNTVmember = [JsonNTVMember *( vSep JsonNTVMember)] NTVsingleValue = JsonValue Figure 6: JsonNTVvalue - ABNF For a NTVsingle, JsonNTVvalue is the NTVvalue. For a NTVlist, JsonNTValue has two representations: * a JsonArray where JsonElements are the JsonNTV of included NTV entities, * a JsonObject where the JsonMembers are the JsonMembers of the JsonNTV of included NTV entities. The corresponding rules are as follows: REQ8: if NTVlistValue has more than one NTV entities and if all NTVname are different and not empty, JsonNTVobject is used, else JsonNTVarray is used _Example:_ _{ ":point" : [2.3522, 48.8566], ":point" : [4.8357, 45.7640] } is not a valid JsonNTV_ 4. Examples Examples of JsonNTV representation of NTV entities: THOMY Expires 7 March 2024 [Page 14] Internet-Draft JSON semantic format (JSON-NTV) September 2023 *Vsingle :* _"lyon"_ _52.5_ _{ ":" : [4.8357, 45.7640] }_ *NVsingle :* _{ "city" : "paris" }_ _{ "paris:" : [4.8357, 45.7640] }_ *TVsingle:* _{ ":point" : [4.8357, 45.7640] }_ *NTVsingle:* _{ "paris:point" : [2.3522, 48.8566] }_ _{ "paris:ntv" : { "coordinate:point" : [4.8357, 45.7640] } }_ *Vlist (composed with JsonArray):* _[4, 45]_ _["paris"]_ _[ [2.3522, 48.8566], {"lyon" : [4.8357, 45.7640]} ]_ _[ { ":point" : [2.3522, 48.8566]}, {":point" : [4.8357, 45.7640]} ]_ _[]_ *Vlist (composed with JsonObject) :* _{ "name": "white", "firstname":"walter", "surname":"heisenberg" }_ _{ "paris:point" : [2.3522, 48.8566] , "lyon" : "france"}_ _{ "paris" : [2.3522, 48.8566], "" : [4.8357, 45.7640]}_ _{ }_ THOMY Expires 7 March 2024 [Page 15] Internet-Draft JSON semantic format (JSON-NTV) September 2023 *NVlist :* _{ "simple list": [4, 45.7]}_ _{ "cities": [{":point": [2.3522, 48.8566]}, {":point": [4.8357, 45.7640]}]}_ *TVlist :* _{ "::point": [[2.3522, 48.8566], {"lyon" : [4.8357, 45.7640]} ] }_ _{ "::dat": [ "2022-01-28T18-23-54Z", "2022-01-28", 1234.78 ] }_ *NTVlist :* _{ "cities::point": [[2.3522, 48.8566], {"lyon": [4.8357, 45.7640]}] }_ _{ "generic date::dat": [ "2022-01-28T18-23-54Z", "2022-01-28", 1234.78]}_ _{ "various::point": [ [2.3, 48.8], { ":date": "2022-01-28"}, {":json": 25 }, { "another NTVlist::json": [1,2,3]} ]}_ *NTVlist and NVlist (composed with JsonObject) :* _{ "cities::point": { "paris": [2.352, 48.856], "lyon": [4.835, 45.764]}}_ _{ "cities": {"paris:point": [2.3522, 48.8566] , "lyon": "france"}}_ 5. Parsing a JsonValue JsonValue is parsed according to JSON structure (from root to leaves). Several steps are considered: * JSON decoding * NTV entity decoding * NTVvalue decoding * NTVtype decoding THOMY Expires 7 March 2024 [Page 16] Internet-Draft JSON semantic format (JSON-NTV) September 2023 5.1. JSON decoding This part is not detailed and consists of: * exploit the JSON structure to identify JsonNTVname and JsonNTVvalue, * extract the following data from the JsonNTVname string: JsonNTVtype, NTVname and singleSep or listSep 5.2. NTV entity decoding The NTV entity is inferred from the JSON structure of JsonValue or JsonNTVvalue: PARS1: The tables Table 1 and Table 2 define the entity identification rules (NTVsingle or NTVlist) +===============+=============+ | JsonValue | NTV entity | +===============+=============+ | JsonPrimitive | Vsingle | +---------------+-------------+ | JsonUnnamed | Vlist | +---------------+-------------+ | JsonArray | Vlist | +---------------+-------------+ | JsonNamed | see Table 2 | +---------------+-------------+ Table 1: Decoding JsonValue THOMY Expires 7 March 2024 [Page 17] Internet-Draft JSON semantic format (JSON-NTV) September 2023 +===========+===============+=============================+ | Separator | JsonNTVvalue | NTV entity | +===========+===============+=============================+ | None | JsonPrimitive | NVsingle | +-----------+---------------+-----------------------------+ | None | JsonNamed | NVsingle | +-----------+---------------+-----------------------------+ | None | JsonUnnamed | NVlist | +-----------+---------------+-----------------------------+ | None | JsonArray | NVlist | +-----------+---------------+-----------------------------+ | ":" | JsonValue | TVsingle or NTVSingle | +-----------+---------------+-----------------------------+ | "::" | JsonUnnamed | NVlist or TVlist or NTVlist | +-----------+---------------+-----------------------------+ | "::" | JsonArray | NVlist or TVlist or NTVlist | +-----------+---------------+-----------------------------+ Table 2: Decoding JsonNTVvalue 5.3. NTVvalue decoding The NTVvalue is inferred from the JsonNTVvalue: PARS2: The NTVvalue of NTVsingle is the JsonNTVvalue. PARS3: The NTVvalue of NTVlist is the list of NTV entities parsed for each JsonElement or JsonMember including in the JsonNTVvalue. 5.4. NTVtype decoding NTVtype is inferred from the JsonNTVtype: PARS4: If JsonNTVtype is a valid NTVtypeLongName NTVtype is the decoded JsonNTVtype, else NTVtype is "json" NTVtype if concatened ParentNTVtypeLongName with JsonNTVtype is empty, else NTVtype is the decoded of concatenation of ParentNTVtypeLongName with JsonNTVtype if it is a valid NTVtypeLongName, else NTVtype is the defaultNTVtype The [JSON-NTV] repository gives some examples of NTV usage. THOMY Expires 7 March 2024 [Page 18] Internet-Draft JSON semantic format (JSON-NTV) September 2023 6. NTV extended structure The NTVvalue of NTV entities are JsonValue. In the NTV extended structure, NTVvalue can be every kind of data. With this structure, the NTV representation is a "json like" data where: * JsonNTVvalue is always NTVvalue, * JsonNTVtype is optional (if NTVtype can be deduced from the NTVvalue), * JsonNTVname is optional (if NTVname can be deduced from the NTVvalue). _Examples of NTV extended representation:_ _{ "date object" : [ datetime.date(2022, 1, 18), datetime.date(2023, 1, 12) ] }_ _this "json like" structure can be converted in JsonNTV format:_ _{ "date object::date" : [ "2022-01-18", "2023-01-12" ] }_ 7. IANA Considerations Any JsonValue is a JsonNTVValue and conversely, any JsonNTVvalue is a JsonValue. Thus, any JSON data may or may not be treated as JsonNTV data, so there is no need to create a specific MIME media type for JsonNTV. All properties of the MIME media type "application/json" are applicable. 8. Security Considerations The format used for NTV data exchanges is the JSON format. So, all the security considerations of [RFC8259] apply. The NTV structure provides no cryptographic integrity protection of any kind. 9. References 9.1. Normative References THOMY Expires 7 March 2024 [Page 19] Internet-Draft JSON semantic format (JSON-NTV) September 2023 [RFC7946] Butler, H., Daly, M., Doyle, A., Gillies, S., Hagen, S., and T. Schaub, "The GeoJSON Format", RFC 7946, DOI 10.17487/RFC7946, August 2016, . [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, . [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, . [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008, . [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data Interchange Format", STD 90, RFC 8259, DOI 10.17487/RFC8259, December 2017, . [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, . 9.2. Informative References [JSON-ND] Kleidon, G., "JSON-ND", 2020, . [JSON-NTV] Thomy, P., "JSON-NTV", 2022, . [OLC] "Google", "Open Location Code", 2016, . [W3C_TAB] "W3C", "Recommendation : Model for Tabular Data and Metadata on the Web", 17 December 2015, . [ISO_3166-1_alpha-2] "ISO", "Codes for the representation of names of countries and their subdivisions - Part 1: Country code", 2020, . THOMY Expires 7 March 2024 [Page 20] Internet-Draft JSON semantic format (JSON-NTV) September 2023 Appendix A. Global NTVtype and Namespace The structure of NTVtype by Namespace makes it possible to have NTVtype or Namespace corresponding to recognized standards at the global level. A standard NTVtype / Namespace is a NTVtype / Namespace defined in the Global Namespace. The standard NTVtype and Namespace are listed below. A.1. Json Json NTVtype have a generic NTVtype : "json" +=======================+=======================+==================+ | NTVtypeName (generic) | NTVvalue | example NTVvalue | +=======================+=======================+==================+ | json | generic NTVtype | | +-----------------------+-----------------------+------------------+ | number (json) | JsonNumber [RFC8259] | 10 | +-----------------------+-----------------------+------------------+ | boolean (json) | JsonBoolean [RFC8259] | "true" | +-----------------------+-----------------------+------------------+ | null (json) | JsonNull [RFC8259] | "null" | +-----------------------+-----------------------+------------------+ | string (json) | JsonString [RFC8259] | "value" | +-----------------------+-----------------------+------------------+ | array (json) | JsonArray [RFC8259] | [1.1, 2.2] | +-----------------------+-----------------------+------------------+ | object (json) | JsonObject [RFC8259] | {"value1": 1, | | | | "value2": 2} | +-----------------------+-----------------------+------------------+ Table 3: Json NTVtype A.2. Numbers +===========================+======================+================+ | NTVtypeName | NTVvalue | comment | +===========================+======================+================+ | int | JsonNumber [RFC8259] | integer | +---------------------------+----------------------+----------------+ | int8, int16, int32, int64 | JsonNumber [RFC8259] | signed | | | | integer | +---------------------------+----------------------+----------------+ | uint8, uint16, uint32, | JsonNumber [RFC8259] | unsigned | | uint64 | | integer | THOMY Expires 7 March 2024 [Page 21] Internet-Draft JSON semantic format (JSON-NTV) September 2023 +---------------------------+----------------------+----------------+ | float | JsonNumber [RFC8259] | floating | | | | point real | +---------------------------+----------------------+----------------+ | float16, float32, float64 | JsonNumber [RFC8259] | floating | | | | point real | +---------------------------+----------------------+----------------+ Table 4: Numbers NTVtype A.3. Datation Datation NTVtype have a generic NTVtype : "dat" THOMY Expires 7 March 2024 [Page 22] Internet-Draft JSON semantic format (JSON-NTV) September 2023 +===========+========================+============================+ |NTVtypeName| NTVvalue | example NTVvalue | |(generic) | | | +===========+========================+============================+ |year | fullyear [RFC3339] | 1998 | +-----------+------------------------+----------------------------+ |month | month [RFC3339] | 10 | +-----------+------------------------+----------------------------+ |day | mday [RFC3339] day of | 21 | | | month | | +-----------+------------------------+----------------------------+ |wday | wday [RFC3339] day of | 7 | | | week | | +-----------+------------------------+----------------------------+ |yday | yday [RFC3339] day of | 360 | | | year | | +-----------+------------------------+----------------------------+ |week | week [RFC3339] | 38 | +-----------+------------------------+----------------------------+ |hour | hour [RFC3339] | 20 | +-----------+------------------------+----------------------------+ |minute | minute [RFC3339] | 18 | +-----------+------------------------+----------------------------+ |second | second [RFC3339] | 54 | +-----------+------------------------+----------------------------+ |dat | generic NTVtype | | +-----------+------------------------+----------------------------+ |date (dat) | date [RFC3339] | "2022-01-28"" | +-----------+------------------------+----------------------------+ |time (dat) | timespec-base [time- | "T18:23:54", "18:23", | | | fraction][RFC3339] | "T18" | +-----------+------------------------+----------------------------+ |timetz | timespec-base [time- | "T18:23:54+0400" | |(dat) | fraction] time- | | | | zone[RFC3339] | | +-----------+------------------------+----------------------------+ |datetime | iso-date-time (without | "2022-01-28T18-23-54" | |(dat) | time-zone)[RFC3339] | | +-----------+------------------------+----------------------------+ |datetimetz | iso-date-time (with | "2022-01-28T18-23-54+0400" | |(dat) | time-zone)[RFC3339] | | +-----------+------------------------+----------------------------+ Table 5: Datation NTVtype THOMY Expires 7 March 2024 [Page 23] Internet-Draft JSON semantic format (JSON-NTV) September 2023 A.4. Period and Duration +=============+===========+=====================================+ | NTVtypeName | NTVvalue | example NTVvalue | +=============+===========+=====================================+ | duration | duration | "P3Y6M4DT12H30M5S" | | | [RFC3339] | | +-------------+-----------+-------------------------------------+ | timearray | JsonArray | [dat1, dat2] | | | | | | | | _dat1, dat2 have "dat" NTVtypeName_ | +-------------+-----------+-------------------------------------+ | period | period | "2022-01-01 / 2022-01-30" | | | [RFC3339] | | | | | "2022-01-01 / P3Y6M4DT12H30M5S" | +-------------+-----------+-------------------------------------+ Table 6: Period and Duration NTVtype A.5. Location Location NTVtype have a generic NTVtype : "loc". The CRS (Coordinate Reference Systems) is geographic, using the World Geodetic System 1984 (WGS 84) datum, with longitude and latitude units of decimal degrees (EPSG:4326). THOMY Expires 7 March 2024 [Page 24] Internet-Draft JSON semantic format (JSON-NTV) September 2023 +==============+=================+===============================+ | NTVtypeName | NTVvalue | example NTVvalue | | (generic) | | | +==============+=================+===============================+ | loc | generic NTVtype | | +--------------+-----------------+-------------------------------+ | point (loc) | Point | [ 5.12, 45.256 ] _(lon, lat)_ | | | coordinates | | | | [RFC7946] | | +--------------+-----------------+-------------------------------+ | multipoint | MultiPoint | [pt1, pt2, pt3] | | | coordinates | | | | [RFC7946] | _ptx has "point" NTVtypeName_ | +--------------+-----------------+-------------------------------+ | line (loc) | LineString | [pt1, pt2, pt3] | | | coordinates | | | | [RFC7946] | _ptx has "point" NTVtypeName_ | +--------------+-----------------+-------------------------------+ | multiline | MultiLineString | [li1, li2, li3] | | | coordinates | | | | [RFC7946] | _lix has "line" NTVtypeName_ | +--------------+-----------------+-------------------------------+ | polygon | Polygon | [rg1, rg2, rg3] | | (loc) | coordinates | | | | [RFC7946] | _rgx has "line" NTVtypeName | | | | (ring)_ | +--------------+-----------------+-------------------------------+ | multipolygon | MultiPolygon | [pl1, pl2, pl3] | | (loc) | coordinates | | | | [RFC7946] | _plx has "polygon" | | | | NTVtypeName_ | +--------------+-----------------+-------------------------------+ | bbox (loc) | Bbox | [ -10.0, -10.0, 10.0, 10.0 ] | | | coordinates | | | | [RFC7946] | | +--------------+-----------------+-------------------------------+ | geojson | geoJSON object | {"type": "point", | | (loc) | [RFC7946] | "coordinates": [40.0, 0.0]} | +--------------+-----------------+-------------------------------+ | codeolc | Open Location | "8FW4V75V+8F6" | | (loc) | Code [OLC] | | +--------------+-----------------+-------------------------------+ Table 7: Location NTVtype THOMY Expires 7 March 2024 [Page 25] Internet-Draft JSON semantic format (JSON-NTV) September 2023 A.6. Structured data +=============+==================+ | NTVtypeName | NTVvalue | +=============+==================+ | row | row [W3C_TAB] | +-------------+------------------+ | field | column [W3C_TAB] | +-------------+------------------+ | tab | table [W3C_TAB] | +-------------+------------------+ | ntv | JsonNTV | +-------------+------------------+ Table 8: Structured NTVtype The data structure associated to this NTVtypeName are defined in specific document. A.7. Normalized String +=============+=========+==========================================+ | NTVtypeName |NTVvalue | example NTVvalue | +=============+=========+==========================================+ | uri |URI | "https://www.ietf.org/rfc/rfc3986.txt" | | |(RFC3986)| | | | | "urn:uuid:f81d4fae-7dec- | | | | 11d0-a765-00a0c91e6bf6" | | | | | | | | "geo:13.4125,103.86673" (RFC5870)" | | | | | | | | "info:eu-repo/dai/nl/12345" | | | | | | | | "mailto:John.Doe@example.com" | | | | | | | | "news:comp.infosystems.www.servers.unix" | +-------------+---------+------------------------------------------+ | email |adress | "John Doe " | | |(RFC5322)| | +-------------+---------+------------------------------------------+ | file |file- | "///path/to/file" | | |hier-part| | | |(RFC8089)| "//host.example.com/path/to/file" | +-------------+---------+------------------------------------------+ Table 9: Structured NTVtype THOMY Expires 7 March 2024 [Page 26] Internet-Draft JSON semantic format (JSON-NTV) September 2023 Keywords are not defined as Normalized String (eg. "id", "mandatory", "units"), they can be used as custom NTVtype (eg. "$id", "$mandatory", "$units") A.8. Namespace The global Namespace includes Namespaces for countries, dependent territories and special areas as defined in [ISO_3166-1_alpha-2] The JsonNamespace for those Namespace is composed by the two digits of the country following by a dot. _Example :_ _"fr." is the France JsonNamespace_ _"un." is The United Nations JsonNamespace_ Each Namespace defines a list of included NTVtype and Namespace. A.9. Custom NTVtype and Namespace Custom NTVtype and Namespace can be created in any Namespace. Table 10 below presents some examples of custom NTVtype. THOMY Expires 7 March 2024 [Page 27] Internet-Draft JSON semantic format (JSON-NTV) September 2023 +================+=========================================+ | JsonNTVtype | comment or JsonNTV example | +================+=========================================+ | "$id" | defined in the global Namespace | | | | | | eg. { ":$id": 5426849" } | +----------------+-----------------------------------------+ | "$iata" | IATA airport code | | | | | | eg. {"Paris Nord:$iata": "CDG"} | +----------------+-----------------------------------------+ | "$uic.station" | UIC station code | | | | | | eg. {"Nantes station:$uic.station" : | | | "8748100"} | +----------------+-----------------------------------------+ | "fr.$city" | NTVtype "city" in "fr." Namespace | | | | | | eg. {":fr.$city" : "Paris"} | +----------------+-----------------------------------------+ | "$schemaorg." | "schemaorg" catalog | | | | | | eg. { ":$schemaorg.propertyID": "NO2" } | | | | | | { ":$schemaorg.unitText": "mg/m3"} | +----------------+-----------------------------------------+ | "$darwincore." | "darwincore" catalog | | | | | | eg. { ":$darwincore.acceptedNameUsage": | | | "Tamias minimus" } | +----------------+-----------------------------------------+ Table 10: Examples of custom NTVtype Appendix B. Complete ABNF notation ; representation of NtvType and Namespace (LongName) NTVtypeLongName = NamespaceParentLongName NTVtypeName NamespaceLongName = NamespaceParentLongName NamespaceName NamespaceParentLongName = NamespaceLongName NamespaceName = [ ["$"] JsonString "." ] ; REQ2 REQ3 NTVtypeName = ["$"] JsonString ; REQ3 ; JSON representation of NTV entities (JsonNTV) THOMY Expires 7 March 2024 [Page 28] Internet-Draft JSON semantic format (JSON-NTV) September 2023 JsonNTV = JsonNTVnamed / JsonNTVsimple ; REQ4 JsonNTVnamed = beginObject JsonNTVMember endObject JsonNTVsimple = JsonNTVvalue JsonNTVMember = JsonNTVname nSep JsonNTVvalue ; Extract of JSON grammar used in this document beginArray = ws "[" ws beginObject = ws "{" ws endArray = ws "]" ws endObject = ws "}" ws nSep = ws ":" ws vSep = ws "," ws ws = *( %x20 / %x09 / %x0A / %x0D ) JsonValue = JsonValue ; indicates that rule is defined in RFC8259 JsonString = JsonString ; indicates that rule is defined in RFC8259 ; JSON representation of NTVname and NTVtype (JsonNTVname) JsonNTVname = NTVname JsonSepType JsonSepType = [singleSep [JsonNTVtype]] / [listSep JsonNTVtype] ; REQ5 REQ6 NTVname = JsonString singleSep = ":" ; NTVsingle separator listSep = "::" ; NTVlist separator ; JSON representation of NtvType (JsonNTVtype) JsonNTVtype = [ NTVtypeLongName / relativeNTVtypeLongName ] ; REQ7 relativeNTVtypeLongName = *NamespaceName NTVtypeName ; REQ7 ; JSON representation of NTVvalue (JsonNTVvalue) JsonNTVvalue = JsonNTVsingleValue / JsonNTVlistValue JsonNTVsingleValue = NTVsingleValue JsonNTVlistValue = JsonNTVarrayValue / JsonNTVobjectValue ; REQ8 JsonNTVarrayValue = beginArray ListJsonNTVvalue endArray THOMY Expires 7 March 2024 [Page 29] Internet-Draft JSON semantic format (JSON-NTV) September 2023 ListJsonNTVvalue = [JsonNTV *( vSep JsonNTV )] JsonNTVobjectValue = beginObject ListJsonNTVmember endObject ListJsonNTVmember = [JsonNTVMember *( vSep JsonNTVMember)] NTVsingleValue = JsonValue Figure 7: Collected ABNF grammar Acknowledgements TBD Contributors TBD Author's Address Philippe THOMY Loco-labs 476 chemin du gaf de Famian 84 500 BOLLENE France Email: philippe@loco-labs.io URI: https://github.com/loco-philippe/NTV/blob/main/README.md THOMY Expires 7 March 2024 [Page 30]