Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 17-Apr-15 15:54pm
v4

1 solution

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900