Skip to content

Config: Support env XRAY_JSON_STRICT=true - #6053

Merged
RPRX merged 2 commits into
XTLS:mainfrom
kastov:json-decode
May 2, 2026
Merged

RPRX merged 2 commits into
XTLS:mainfrom
kastov:json-decode

Conversation

@kastov

@kastov kastov commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

The custom JSON reader strips comments and other non-standard JSON5/JSONC syntax to make local configs human-friendly. On large configs (millions of users) it adds substantial overhead — both from byte-by-byte FSM and from io.TeeReader buffering the entire input.

Enable by env variable: xray.json.strict=1

@Fangliding

Copy link
Copy Markdown
Member

为啥假设其他人用的远程config就是没注释的 就你家用这个功能其他人不活了?

@kastov

kastov commented May 1, 2026 •

Copy link
Copy Markdown
Contributor Author

为啥假设其他人用的远程config就是没注释的 就你家用这个功能其他人不活了?

Standard JSON serializers (json.Marshal, JSON.stringify, etc.) physically can't emit comments

@Fangliding

Fangliding commented May 1, 2026 •

Copy link
Copy Markdown
Member

答非所问 为什么假设所有使用远程下发的人没有和文件一样的注释需求

@kastov

kastov commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

How can they use comments if the code doesn't allow them to add them? Again, there's the JSON standard. Many frameworks return response bodies in JSON. They won't allow any comments to be added to it, as that would violate the standard.

@Fangliding

Copy link
Copy Markdown
Member

这又不是web标准 只是获取一个文件而已 这种情况非常简单 一个人有许多服务器 在一台中心服务器上存放config并配置一个nginx访问 不允许他在这种情况给配置文件写注释?

@RPRX

RPRX commented May 1, 2026

Copy link
Copy Markdown
Member

这个。。。严格来说 Xray-core 所支持的 JSON 本来就不是标准 JSON4,而是允许写注释,是 JSON5 还是 JSONC 我不清楚

如果是 performance 问题的话需要说明对性能会有多严重的影响,比如内存占用多几百兆,还是启动时间多几十秒(虽然我觉得对于承载 millions of users 的服务器也不差这几百兆,且又不是总是在重启)

如果你们确实需要这项改动,可以加个启动参数,比如 --strict

@Fangliding

Fangliding commented May 1, 2026 •

Copy link
Copy Markdown
Member

改成一个环境变量 xray.json.strict 这个为1就跳过自定义解析器就行了 只是看着为了烂机场应用就改默认行为很不爽

@kastov

kastov commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

如果你们确实需要这项改动,可以加个启动参数,比如 --strict

Sure

@kastov kastov changed the title Performance: skip custom JSON reader for remote configs Performance: skip custom JSON reader with env variable xray.json.strict May 1, 2026
@kastov

kastov commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

xray.json.strict=1 added.

@Fangliding

Copy link
Copy Markdown
Member

环境变量是用 platform.NewEnvFlag 那套东西的 不是直接读

@RPRX

RPRX commented May 1, 2026

Copy link
Copy Markdown
Member

别环境变量吧,加参数不好吗

@Fangliding

Copy link
Copy Markdown
Member

xray的flag是要自己解析的 这种事都是环境变量弄

@kastov

kastov commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

环境变量是用 platform.NewEnvFlag 那套东西的 不是直接读

sorry, fixed

@RPRX

RPRX commented May 1, 2026

Copy link
Copy Markdown
Member

但是 xray run 它本来就可以接收参数,能设计成参数为啥搞环境变量那边

@Fangliding

Copy link
Copy Markdown
Member

因为 ./xray

@RPRX

RPRX commented May 1, 2026

Copy link
Copy Markdown
Member

那就环境变量吧

@RPRX

RPRX commented May 2, 2026

Copy link
Copy Markdown
Member

参考其它环境变量,改为了 XRAY_JSON_STRICT=true 时不接受带注释的 JSON

@RPRX RPRX changed the title Performance: skip custom JSON reader with env variable xray.json.strict Config: Support env XRAY_JSON_STRICT=true May 2, 2026
@RPRX
RPRX merged commit bdff2fa into XTLS:main May 2, 2026
39 checks passed
@bytecategory

Copy link
Copy Markdown
Contributor

为啥假设其他人用的远程config就是没注释的 就你家用这个功能其他人不活了?

你为什么讨厌机场? 机场恰恰能暴露xray的很多问题, 很多不起眼的开销会被放大很多, 促使它的改进. 而且他做的还是个开关...

wyusgw pushed a commit to wyusgw/Xray-core that referenced this pull request Sep 15, 2026
@kastov
kastov deleted the json-decode branch October 20, 2026 23:15
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.

4 participants