如何获取在React应用程序中使用的可能使用的JSON模式格式值的列表?
我们正在开发一个React应用程序,需要获取JSON Schema标准内置格式的列表。根据 json-schema /a>内置格式如下:
- 日期和时代
- 电子邮件地址
- 主机
- 名地址
- 等。
如果我不必在应用程序中进行硬编码,那么我宁愿如何检索那些可能的列表以编程方式值?
[edit]
一个澄清,我们正在开发一个JSON模式,该模式设置“ $ schema”:“ http://json-schema.org/schema”
。这就是应用程序能够确定我们正在使用当前JSON模式规范的方式。从那里开始,我们正在寻找一种加载“格式”
的可能值的方法,以便我们可以将其显示在UI中。
We are developing a REACT application that needs to get a list of the JSON schema standard built-in formats. According to json-schema.org reference page the built-in formats are as follows:
- Dates and times
- Email addresses
- Hostnames
- IP Addresses
- etc.
I'd rather if I didn't have to hardcode those values in our application, so how can we retrieve a list of those possible values programmatically?
[EDIT]
A clarification, we are developing a JSON schema that sets "$schema": "http://json-schema.org/schema"
. This is how the app would be able to identify that we are using the current JSON Schema specification. From there we are looking for a way to load possible values for "format"
so we can present it in the UI.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$ schema
指示声明正在使用的模式的规范版本。规范的每个版本都会声明一组(小)静态格式。
通过
$ schema
值进行硬编码将这些集进行硬编码并非不合理。除非您正在编写自己的元式schemas,否则只有4或5个(如果包括草稿4)值。我将它们硬编码到我的JSON模式库中, jsonschema.net 。
如果您正在寻找一种自动化方法来找到这些值,则必须自己扫描规范文档。它们没有在元式schemas中列出,这是您导航到URI(而非URL)在
$ $ schema
中找到的。 Meta-Schema仅要求格式
的值是字符串。该规范有意留下这一开放式,以便人们可以创建自己的自定义格式。
$schema
indicates the version of the specification that the schema that declares it is using.Each version of the specification declares a (small) static set of available formats.
It's not unreasonable to hardcode these sets into a lookup by
$schema
value. There are only 4 or 5 (if you include draft 4) values for this keyword, unless you're writing your own meta-schemas.I've hardcoded them into my JSON Schema library, JsonSchema.Net.
If you're looking for an automated way to find these values, you're going to have to scan the specification documents themselves. They're not listed in the meta-schemas, which is what you get when you navigate to the URI (not a URL) find in
$schema
. The meta-schema just requires thatformat
's value is a string.The specification intentionally leaves this open-ended so that people can create their own custom formats.