JSON架构设计:多个数组属性还是一个? [英] JSON schema design: multiple array properties or one?

查看:75
本文介绍了JSON架构设计:多个数组属性还是一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSON Schema。



我正在尝试在两种方式之间决定构建模式的一部分:



A和B是两种类型的配置文件(对象)。它们共享相似的属性并且只有几个不同(基本上,从应用程序的角度来看,A和B是从称为profile的基类派生的类)



我正在使用JSON(使用我的预定义架构)加载配置文件数据。



第一个JSON想法(一个数组属性中的对象和B对象称为配置文件):

profiles:[{ A:{{}}},{A:{...}},{B:{...}},...]



第二个JSON想法(一个对象和B对象在不同的​​数组中):

AllAs:[{...},{...},{...}]

AllBs:[{...},{...},{...}]



记住:A和B来自个人资料。



哪种想法在技术上听起来更好?我喜欢第一个(加载时,我可以将它们全部放在一个类型为Profile的列表中)。这个对我来说最有意义,但我已经看到一些想法2.



虽然想法2可以让你更容易快速找到所有的As或Bs,无需在以后过滤类型(不困难,但这是一个额外的步骤)。



我知道两者都可以毫无困难地工作(并且使用架构的应用程序不一定要在内部遵循任何一个想法),但我正在尝试创建一个可供其他人使用的开放式架构,所以我希望它尽可能干净。



有什么想法吗?

I'm working on something with JSON Schema.

I'm trying to decide between two ways to structure a part of the schema:

A and B are two types of profiles (objects). They share similar properties and differ by only a few (basically, A and B from the application point of view are classes derived from a base class called "profile")

I'm loading the profile data using JSON (with my predefined schema).

First JSON idea (A objects and B objects in one array property called "profiles"):
"profiles" : [ {"A": { ... } }, {"A": { ... } }, { "B": { ... } }, ...]

Second JSON idea (A objects and B objects in separate arrays):
"AllAs" : [ { ... }, { ... }, {... }]
"AllBs" : [ { ... }, {...}, {...}]

Remember: A and B are derived from profile.

Which idea sounds technically better? I like the first (when loading, I could just put them all in one List of type Profile). this one makes the most sense to me, but I've seen some do idea 2.

While idea 2 may make it easier to quickly find all As or Bs, without having to filter the types later on (not difficult, but it is an extra step).

I know both really will work without much trouble (and the application using the schema is not necessarily required to follow either idea internally), but I'm trying to create an open schema that can be used by other people, so I want it to be as clean as possible.

Any ideas?

推荐答案

我会选择:

I would go for :
{
"profiles" : {
          "A" : [ {}, {}, {}],
          "B" : [ {} ]
   }
}



这会给你C,D等空间。


Which would give you room for "C","D" etc.


这篇关于JSON架构设计:多个数组属性还是一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆