使用可替换值解析 JSON

发布于 2025-01-12 11:45:39 字数 270 浏览 3 评论 0原文

目前是否有任何语法允许在 .json 中替换值?

如果没有,我会建议拥有这种能力。 毕竟已经是 2022 年了,我们难道不应该能够轻松填充值而不必编写自己的解析器吗?

简单的例子:

{ "%h" : "某个值", 这

将用系统特定的主机名替换“%h”,并且如果“参数”不存在,则完全是选项,解析中不会发生任何变化。

如果 .json 具有特定的原生“参数”语法,那就没问题。 只是想法,我们可以有这个选项,“%h”或“”,无论 .json 想要什么语法。

Is there currently any syntax to allow for replaceable values in a .json ?

If not I would propose to have this capability.
After all this is 2022 shouldn't we be able to populate values easily without have to write our own parsers?

simple example:

{
"%h" : "some value",
}

this would replace "%h" with the system specific hostname, and would be completely option, if the "parameter" does not exist, no change in the parse.

And if .json has a specific "parameter" syntax that is native to them, that's fine.
Just the idea, we could have this option, "%h", or "", whatever syntax .json would like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-01-19 11:45:39

JSON 标准不允许动态值。它是一种非常简单的文本表示格式,用于编码数据交换 标准出版物是这样描述的:

JSON 是一种轻量级、基于文本、独立于语言的语法,用于定义数据交换格式。它源自 ECMAScript 编程语言,但独立于编程语言。 JSON 定义了一小组用于结构化数据的可移植表示的结构化规则。

本规范的目标只是定义有效 JSON 文本的语法。其目的不是提供符合该语法的文本的任何语义或解释。它还故意没有定义如何将有效的 JSON 文本内化到编程语言的数据结构中。有许多可能的语义可以应用于 JSON 语法,并且可以通过编程语言处理或映射 JSON 文本的多种方式。使用 JSON 进行有意义的信息交换需要相关各方就要应用的特定语义达成一致。定义 JSON 的特定语义解释可能是其他规范的主题。同样,JSON的语言映射也可以独立指定。例如,ECMA-262 定义了有效 JSON 文本和 ECMAScript 运行时数据结构之间的映射。

因此无法定义某种模板值。您可以通过单独处理 JSON 来实现此类功能,但这取决于您使用的技术堆栈和工具。但是,它仅适用于您的项目,不适用于任何其他第三方项目。

The JSON standard does not allow for dynamic values. It is a very simple text representation format meant for encoding data interchange the standard publcation describes it like this:

JSON is a lightweight, text-based, language-independent syntax for defining data interchange formats. It was derived from the ECMAScript programming language, but is programming language independent. JSON defines a small set of structuring rules for the portable representation of structured data.

The goal of this specification is only to define the syntax of valid JSON texts. Its intent is not to provide any semantics or interpretation of text conforming to that syntax. It also intentionally does not define how a valid JSON text might be internalized into the data structures of a programming language. There are many possible semantics that could be applied to the JSON syntax and many ways that a JSON text can be processed or mapped by a programming language. Meaningful interchange of information using JSON requires agreement among the involved parties on the specific semantics to be applied. Defining specific semantic interpretations of JSON is potentially a topic for other specifications. Similarly, language mappings of JSON can also be independently specified. For example, ECMA-262 defines mappings between valid JSON texts and ECMAScript’s runtime data structures.

Therefore there is no way to define a template value of some sort. You can achieve such functionality by processing your JSON separately but that would depend on the technology stack and the tools you use. However, it would only work for your project, not in any other third party projects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文