You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSON is an ubiquitous format used in many applications. There is no single way of storing JSON values depending on the context, sometimes leading some applications to use multiples representations of JSON values in the same place. This can cause a problem for JSON processing libraries that should not care about the actual internal representation of JSON values, but are forced to stick to a particular format, leading to unwanted and costly conversions between the different formats.
I am currently working on the json-ld library that provides an implementation of the JSON-LD data interchange format, based on JSON. One of my goals is to provide useful error reports when the input JSON document cannot be processed. This includes pinpointing the exact line-column position of the error, something that cannot be done with serde_json since code-mapping metadata is not kept by the parser. That is why I am also working on a JSON parsing crate providing such information. However I do not want to force my users to use my crate over serde_json whenever precise error reports are not needed.
To solve this issue, my idea was to define common JSON features in a dedicated library, generic-json (still a work in progress), defining a basic Json trait abstracting away implementation details and a standard Value type defining the structure of a JSON value. This could give something like this:
/// JSON document with metadata.pubtraitJson{/// Metadata associated to each JSON value./// In the case of `serde_json` this would be `()`./// In my case, that would be a more complicated type including code-mapping info.typeMetaData;/// Number type.typeNumber;/// String type.typeString;/// Array type.typeArray;/// Object key type.typeKey;/// Object type.typeObject;}pubtraitMetaValue<T:Json>{fnmetadata(&self) -> &T::Metadata;fnvalue(&self) -> &Value<T>;}pubenumValue<T:Json>{Null,Bool(bool),Number(T::Number),String(T::String),Array(T::Array),Object(T::Object)}
Would you be open to rely on such crate to define the Value type and improve interoperability with other JSON crates?
Your Value type definition would become something like:
In practice, that would not change anything about the Value type except that its actual definition would end up in an upstream crate. In theory, you would not need a major release for this. What do you think? I can open a PR for this (once the we agree on the content of the generic-json crate).
The text was updated successfully, but these errors were encountered:
Well even if it is in theory possible, having Value as an upstream type is too cumbersome. Instead, I propose to have a ValueRef type that holds reference to the inner data of the value:
Pros: the definition of Value stays in the crate, nothing is removed. My proposition could even be feature gated.
Cons: this adds a level of translation between Value and ValueRef, but I think it is a small price to pay to gain interoperability.
JSON is an ubiquitous format used in many applications. There is no single way of storing JSON values depending on the context, sometimes leading some applications to use multiples representations of JSON values in the same place. This can cause a problem for JSON processing libraries that should not care about the actual internal representation of JSON values, but are forced to stick to a particular format, leading to unwanted and costly conversions between the different formats.
I am currently working on the
json-ld
library that provides an implementation of the JSON-LD data interchange format, based on JSON. One of my goals is to provide useful error reports when the input JSON document cannot be processed. This includes pinpointing the exact line-column position of the error, something that cannot be done withserde_json
since code-mapping metadata is not kept by the parser. That is why I am also working on a JSON parsing crate providing such information. However I do not want to force my users to use my crate overserde_json
whenever precise error reports are not needed.To solve this issue, my idea was to define common JSON features in a dedicated library,
generic-json
(still a work in progress), defining a basicJson
trait abstracting away implementation details and a standardValue
type defining the structure of a JSON value. This could give something like this:Would you be open to rely on such crate to define the
Value
type and improve interoperability with other JSON crates?Your
Value
type definition would become something like:In practice, that would not change anything about the
Value
type except that its actual definition would end up in an upstream crate. In theory, you would not need a major release for this. What do you think? I can open a PR for this (once the we agree on the content of thegeneric-json
crate).The text was updated successfully, but these errors were encountered: