这是有效的json吗?

{
    "a" : "x",
    "a" : "y"
}

http://jsonlint.com/表示同意.

http://www.json.org/ doesn't say anything about it being forbidden.

但很明显这没有多大意义,是吗?

推荐答案

the standard (p. ii)开始:

预计其他标准将引用此标准,严格遵循JSON文本格式,而 对各种编码细节施加限制.这样的标准可能需要特定的行为.JSON 其本身并没有规定任何行为.

Further down in the standard (p. 2), the specification for a JSON object:

An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string. A single colon token follows each name, separating the name from the value. A single comma token separates a value from a following name.

JSON对象图表

它没有提到任何重复的键是无效或有效的,所以根据规范,我可以安全地假设这意味着它们是允许的.

That most implementations of JSON libraries do not accept duplicate keys does not conflict with the standard, because of the first quote.

Here are two examples related to the C++ standard library. When deserializing some JSON object into a std::map it would make sense to refuse duplicate keys. But when deserializing some JSON object into a std::multimap it would make sense to accept duplicate keys as normal.

Json相关问答推荐

JOLT将对象名作为新属性添加到主体中

在scala中将字符串列转换为 struct 的JSON映射

如何使用JQ打印每个根级对象键一行?

Allof Indide的JSON模式之一

处理输入数据并转换为更简单的格式-PowerBI

JSON API返回多个数组,需要帮助拼合数据以存储在SQL Server数据库表中

使用自定义类型在Golang中解析JSON数组

如何按键过滤

使用 JQ 获取 JSON 中的替代元素(输出:JSON 对象)

使用 TypeScript 接口时如何修复未定义错误?

如何 Select 一个值,这是可选的 - 使用 jq

通过一个序列化器更新多个模型数据

当值包含ansible中的字符串时解析json值

PowerShell - JSON/PsCustomObject - 为什么我的数组被扁平化为一个对象?

Jackson Json:如何将数组转换为 JsonNode 和 ObjectNode?

什么是类型和类型令牌?

以 unicode 将 pandas DataFrame 写入 JSON

如何使用 Jackson 注释从 HttpResponse 反序列化 JSON 对象?

从调试器获取 IntelliJ Idea 中的 JSON 对象

如何在 JAVA 中对 JSONArray 进行排序