specs icon indicating copy to clipboard operation
specs copied to clipboard

JSON Example: Fix all types

Open ma30002000 opened this issue 3 years ago • 4 comments

Apparently, in the Analytics JSON example, except for Frame/Object/Appearance/Color/ColorCluster/Color/Weight, all attribute values have been encoded as strings instead of their JSON types number or the boolean values. This pull request fixes that. I have double-checked the data types against the respective XML/XSD schema files.

ma30002000 avatar Jun 20 '22 07:06 ma30002000

As far as I know we were targeting a simple xml to json conversion logic and the example is as per the conversion table defined, if proper type conversion is required then the xml to json convertor should have prior knowledge of xml schema.

sujithhanwha avatar Jul 19 '22 01:07 sujithhanwha

I agree with Sujith on this. I think all values should be strings. Otherwise the translator needs deep knowledge about the schema. If all values are strings the translation is very easy to implement.

I do not agree that loosing all type information is a good idea. If you are actually using code generators (based e.g. on a JSON Schema) for validation and parsing for typed languages like https://quicktype.io/, the automatic validation and conversion to a specific type will not take place and would have to be done manually (and very error-pronely) afterwards.

In general, all validation of the JSON output via a JSON schema will not be very thorough (well, basically not useful at all) when types are non-existent.

In my opinion "native" usability, expressiveness and validatability and of the JSON data structures should be considered more important than apparent "ease" of a xml/json conversion, especially considering that JSON data structures will probably be used where XML data structures are not.

ma30002000 avatar Jul 21 '22 08:07 ma30002000

Any updates on my points?

ma30002000 avatar Jul 28 '22 18:07 ma30002000

Any updates on my points?

Agree that preserving type in json is very useful in many use cases, but the example is simply following the conversion table defined in "5.4.3 JSON payload format" section. It would be better to update this section, either by updating the table or by adding a special note on preserving data types.

sujithhanwha avatar Jul 28 '22 23:07 sujithhanwha

See also PR #246 as a per-requisit.

HansBusch avatar Aug 18 '22 13:08 HansBusch