Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON schema : allow to store information in keys
    primarykey
    data
    text
    <p>I want to formally define a schema for a JSON-based protocol. I have two criteria for the schema: 1. I want to be able to use tools to create parser/serializer (php and .net). 2. Result JSON should be easy to human-read</p> <p>Here is the context. The schema will be describing a game character, as an example I will take one aspect of the profile - professions. A character can have up to 2 professions (from a list of 10), each profession is described by a name and a level, e.g.:</p> <p>Skinning - level 200 Blacksmith - level 300</p> <p>To satisfy criterion #1 it really helps to have XSD schema (or JSON Schema) to drive code generator or a parser library. But that means that my JSON must look something like:</p> <pre><code>character : { professions : [ { profession : "Skinning", level : 525 } { profession : "Blacksmith", level : 745 } ] } </code></pre> <p>but it feels too chatty, I would rather have JSON look like (notice that profession is used as a key):</p> <pre><code>character { professions : { "Skinning" : 525, "Blacksmith" : 745 } } </code></pre> <p>but the later JSON can not be described with XSD without having to define an element for each profession.</p> <p>So I am looking for a solution for my situation, here are options I have identified:</p> <ol> <li>shut up and make JSON XSD-friendly (first snippet above)</li> <li>shut up and make JSON human-friendly and hand-code the parser/serializer.</li> </ol> <p>but I would really like to find a solution that would satisfy both criteria.</p> <p>Note: I am aware that Newton-King's JSON library would allow me to parse professions as a Dictionary - but it would require me to hand code the type to map this JSON to. Therefore so far I am leaning towards option #2, but I am open to suggestions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload