Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

切换 JSON 库 #378

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

切换 JSON 库 #378

wants to merge 1 commit into from

Conversation

LuoZijun
Copy link
Contributor

@LuoZijun LuoZijun commented Jan 6, 2021

JSON语法规范背景

基本上,绝大部分的 JSON 库实现的是 IETF 制定的 RFC-8259。而 IETF 制定的这份标准基本和 ECMAScript-2011 里面的文法保持一致。

ECMAScript 在版本 2011 发布之后,后续的版本语法发生了较大的改变,连带影响到 JSON 语法的基本就是 String Literals,以及增加了一些起控制功能字符。

在 ECMAScript-2011 之后的版本里面,String Literals 里面的转义序列支持了 \u{CodePoint},以及\NonEscapeCharacter。除此之外,其余的部分则没有变化。

JSON5 语法扩展:

Spec: json5

JSON-5 扩展从 ECMAScript 的语法当中,抽取了不少语法来作为 JSON 语法的扩展,如:

  • 支持单行和多行的注释语法
  • Object 和 Array 的成员结尾可以尾随一个逗号
  • 支持单引号作为 String 的界定符
  • String 的转义序列更加丰富

新的 JSON 库和当前使用的 JSON 库有何区别?

目前使用的 JSON 库为:callum-oakley/json5-rs

准备切换至: LuoZijun/json-rust

切换原因:当前使用的 json 库,有更多的依赖,以及更大的构建时开销,同时影响着最终的 binary 的大小。

比较:

RFC-8259 ECMAScript® 2020 JSON-5 EXT
json ❌ (不能处理 \u{CodePoint}) 仅支持2条扩展:1) 单行和多行注释 2) Object 和 Array 支持尾随逗号
json5 ❌ (不能处理 \u{CodePoint}) 几乎全部支持,除了不能处理 \NonEscapeCharacter

@zonyitoo
Copy link
Collaborator

@dev4u 当前master就支持注释

@dev4u
Copy link

dev4u commented Mar 17, 2021

@dev4u 当前master就支持注释

嗯,是的,我错了。

@chuxi
Copy link
Contributor

chuxi commented Sep 1, 2022

I do not think it is a good idea to merge such a pull request.

The json5 lib in pull request is a fork from personal github repo, which is not stable enough. the original repo is not well maintained by authors.

I searched the json5 supported libraries. the Serde framework supports json5, which is stable and widely used in many projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants