哪些有效的JSON文件不是有效的YAML 1.1文件? [英] What valid JSON files are not valid YAML 1.1 files?

查看:66
本文介绍了哪些有效的JSON文件不是有效的YAML 1.1文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YAML 1.2是一个超集(其中一个有关重复密钥的次要警告) JSON,因此任何有效的JSON文件也是有效的YAML文件.但是, YAML 1.1规范(其中

YAML 1.2 is (with one minor caveat regarding duplicate keys) a superset of JSON, so any valid JSON file is also a valid YAML file. However, the YAML 1.1 specification (which has the most library support) doesn't mention JSON. Most valid JSON files are valid YAML 1.1 files, but I found at least one exception by experimenting with PyYaml and Python's standard JSON library:

  • a double-precision floating-point overflow such as 12345e999 is interpreted as a string by PyYAML and IEEE infinity by Python's JSON library.

是否有任何差异的完整列表,其确定性要比通过测试特定实现中的边缘情况更可靠地确定? (也就是说,通过比较规范?)例如,我想生成JSON字符串,该字符串将由JSON解析器和YAML 1.1解析器以相同的方式解释:我必须在字符串上施加哪些约束?

Does anyone have a complete list of differences, determined more robustly than by testing edge cases in a particular implementation? (That is, from a comparison of the specifications?) For example, I want to generate JSON strings that will be interpreted the same way by a JSON parser and a YAML 1.1 parser: what constraints must I place on my strings?

推荐答案

请参见此处 (特别是脚注25).它说:

See here (specifically footnote 25). It says:

不兼容性如下:JSON允许扩展字符 像UTF-32这样的集合,并且具有不兼容的Unicode字符转义语法 相对于YAML; YAML在逗号, 等于冒号,而JSON不等于.一些非标 JSON的实现扩展了语法,使其包含Javascript的 /*...*/评论.处理这种边缘情况可能需要光照 在解析为内联YAML之前对JSON进行预处理

The incompatibilities were as follows: JSON allows extended character sets like UTF-32 and had incompatible unicode character escape syntax relative to YAML; YAML required a space after separators like comma, equals, and colon while JSON does not. Some non-standard implementations of JSON extend the grammar to include Javascript's /*...*/ comments. Handling such edge cases may require light pre-processing of the JSON before parsing as in-line YAML

另请参见 https://metacpan.org/pod/JSON :: XS#JSON-and-YAML

相关
YAML和JSON有什么区别?什么时候比另一个更喜欢

这篇关于哪些有效的JSON文件不是有效的YAML 1.1文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆