-
-
Save deoxxa/6e7a26106e06bf540999 to your computer and use it in GitHub Desktop.
{ | |
"id": 1, | |
"title": "Hello, World!", | |
"content": "This is a sample blog post.", | |
"tags": ["sample", "hello world"], | |
"comments": [ | |
{"name": "User A", "email": "user.a@example.com", "time": "Sat Jul 02 2011 12:43:21 GMT+1000 (EST)", "comment": "Great post!"}, | |
{"name": "User B", "email": "user.b@example.com", "time": "Sat Jul 02 2011 11:45:47 GMT+900 (JST)", "comment": "I agree with User A"} | |
] | |
} |
"blog_post": { | |
"type": ["hash"], | |
"children": { | |
"id": { | |
"type": ["numeric"] | |
}, | |
"title": { | |
"type": ["text","text_extended"], | |
"attributes": { | |
"text_extended_max_length": 120 | |
} | |
}, | |
"content": { | |
"type": ["text"] | |
}, | |
"tags": { | |
"type": ["list"], | |
"items": { | |
"type": ["text","text_extended"], | |
"attributes": { | |
"text_extended_max_length": 30 | |
} | |
} | |
}, | |
"comments": { | |
"type": ["list"], | |
"items": { | |
"type": ["hash"], | |
"children": { | |
"name": { | |
"type": ["text","text_extended"], | |
"attributes": { | |
"text_extended_max_length": 40 | |
} | |
}, | |
"email": { | |
"type": ["text","text_extended"], | |
"attributes": { | |
"text_extended_max_length": 100 | |
} | |
}, | |
"time": { | |
"type": ["text","text_timestamp"] | |
}, | |
"comment": { | |
"type": ["text","text_extended"], | |
"attributes": { | |
"text_extended_max_length": 10000 | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Well, it depends on the intended use I suppose. The reason mine is so verbose is to try to reduce the amount of time I have to spend configuring/specialising client applications as much as possible (effectively this project is a one-man show at my workplace...). It's at the point now where I hardly ever have to modify a client application to use a new resource, having client libraries for different languages and plugins for different applications that implement all of my category I, II and III types (including things like dates, times, coordinates, temperatures, speeds, ranges, etc) so they just magically work.
As far as I understand, you're looking to provide some sort of WSDL-like functionality as well, so keeping things simple and having clear restrictions in place is almost definitely the way to go. I was just making the point that schema definitions for JSON documents have their uses and can be incredibly handy in certain situations :).
And, of course, the JSchema would be:
{
"id": "integer",
"title": "string",
"content": "string",
"tags": ["string"],
"comments": [
{"name": "string", "email": "string", "time": "date", "comment": "string"},
]
}
So I guess the question is: does the simplicity of this form make up for the lack of metadata?