admin管理员组文章数量:1320780
I have a object something like:
{
"category|subCategory" : value
}
Is it wrong to use "|" (which I intend to use as a delimiter) in key of an object?
I have a object something like:
{
"category|subCategory" : value
}
Is it wrong to use "|" (which I intend to use as a delimiter) in key of an object?
Share Improve this question asked Sep 28, 2017 at 6:42 rudy0807rudy0807 1521 silver badge8 bronze badges 4- 3 It is neither "right" nor "wrong". It is valid, and that's all that really matters – Mulan Commented Sep 28, 2017 at 6:43
- 2 Yes it's valid. But you won't be able to access the object property by dot notation. – abhishekkannojia Commented Sep 28, 2017 at 6:45
- Yes, I am using the property using ["category|subCategory"], so thanks for the ment :) – rudy0807 Commented Sep 28, 2017 at 6:52
- Separator characters are normally chosen from the set of characters that are not already being used. Pipe is often a good character for this in many data sets. Looking at mon Redis use, which uses this paradigm a lot to form posite keys, the pipe char and the colon appear most often. Colon is very popular for this purpose as it has a similar language meaning but it's only usable if you're sure you won't find colon appearing as valid characters in the individual keys. – NeilG Commented Dec 11, 2023 at 13:42
2 Answers
Reset to default 6It is valid. Property names may be any string.
Wrongness seems like a moral judgement that is a matter of opinion.
According to the standard, any string
can be used as the key.
A string is a sequence of Unicode code points wrapped with quotation marks (U+0022). All code points may be placed within the quotation marks except for the code points that must be escaped: quotation mark (U+0022), reverse solidus (U+005C), and the control characters U+0000 to U+001F.
Even {"⛄|⛱|☠": "is valid"}
is valid.
本文标签: javascriptIs it wrong to use Pipe symbol () in a json keyStack Overflow
版权声明:本文标题:javascript - Is it wrong to use Pipe symbol (|) in a json key? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742088489a2420123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论