Json Schema vs JObject

64 views
Skip to first unread message

michelle sollicito

unread,
Nov 21, 2017, 8:25:51 AM11/21/17
to JSON Schema
Ok its my understanding that Json Schema is a way of describing the "shape" of an object and JObject is an object that may or may not comply to the schema (or "shape")..  am I right?  Because my work colleagues seem to be mixing up Schema and Data to me.. they want to extent the JsonSchema object to add in data and I dont think that sounds right?

I see it as similar to in a database - data does not go into the schema definition (the CREATE TABLE statement) it goes into the object created using the schema 

My code below matches how I understand we should use the schema

                JsonSchema schema = null;

                try

                {   //schemaJson holds the description of the object "shape" - ie what properties it has and what type they are

                    string schemaJson = @"{

                        'description':'material',

                        'type':'object',

                        'properties':{ 

                             'srn':{ 

                                 'type':'string'

                              },

                              'restriction':{ 

                                 'type':'string'

                              },

                              'id':{ 

                                 'type':'string'

                              },

                              'source':{ 

                                 'type':'string'

                              },

                              'schema':{ 

                              'type':'string'

                              },

                              'ref':{ 

                              'type':'string'

                              },

                              'title':{ 

                              'type':'string'

                              },

                              'description':{ 

                              'type':'string'

                              },

                        }

                    }";

                    var sJson = schemaJson.ToString();

                    //schema now holds the JsonSchema describing what the object should look like in terms of "shape" (properties etc)

                    schema = JsonSchema.Parse(sJson);

                }

                catch(Exception ex)

                {

                    string str = ex + "";

                }

                try

                {

                    JObject fieldsRequest = JObject.Parse(@"{

                    'srn': 'srnstring',

                    'restriction': 'Client',

                    'id': '36d5c83c-db06-4ebb-aaf9-b146a54e7b1c',

                    'source': 'F1',

                    'schema': 'MaterialsFieldsRequest',

                    'ref': 'form-Uri-ReferenceEquals',

                    'title': 'FieldType',

                    'description': 'This is the FieldType',

                    }");

                   

                    //fieldsRequest is a JObject that may or may not be a valid implementation of that schema

                    bool valid = fieldsRequest.IsValid(schema);  //is it a valid implementation?

                    if (valid)

                        material.Fields = fieldsRequest;   //if valid use the JObject

                   

                }

                catch (Exception ex)

                {

                    //ToDo: if not valid, do what?

                }

 

Colleagues are saying they want the Payload to be completely Json Schema and the whole Response object to be completely Json Schema - but of course these have to contain DATA not the DESCRIPTION of data - so this confuses me and does not make sense to me


Help!  Am I misunderstanding something vital here?  These guys are much brighter than me so I fear I must have the fundamentals all wrong?

Ben Hutton (@Relequestual)

unread,
Nov 21, 2017, 8:32:20 AM11/21/17
to JSON Schema
Hi Michelle,

You are correct...

"JSON Schema is a vocabulary that allows you to annotate and validate JSON documents." - json-schema.org

Either your colleague is missinformed, or doesn't mean what you understand them to mean.

The schema tells you the FORMAT of the JSON. Maybe they aren't aware of JSON Schema, and mean that the request and response should be valid JSON format.

Have you tried directing them to json-schema.org?

michelle sollicito

unread,
Nov 22, 2017, 4:31:45 AM11/22/17
to JSON Schema
Thank you for your response!  These guys are very clever (much cleverer than me) and definitely know of json-schema.org but they think I am "overcomplicating" things - this is what my boss says he wants to do (which makes no sense to me!)

I’m not seeing a reason to over complicate things, why can’t we extend JsonSchema as discussed? Such as:

 

       public class MaterialExtension

       {

              public string Srn { get; set; }

              public string Restriction { get; set; }

              public string Id { get; set; }

              public string Source { get; set; }

              public string Category { get; set; }

              public string FormUri { get; set; }

              public string CountryCode { get; set; }

              public string RegionCode { get; set; }

       }

 

       public class Material : JsonSchema

       {

              [JsonProperty(PropertyName = "x-st")]

              public MaterialExtension Extension { get; set; }

       }

Ben Hutton (@Relequestual)

unread,
Nov 22, 2017, 4:52:05 AM11/22/17
to JSON Schema
Hi Michelle,

I think maybe THIS is where you're getting confused.

It seems you're talking about a library or specific implementation of JSON Schema.
JSON Schema is not code, it's a specification.

What you have pasted means nothing to me, sadly. I don't even know for sure what language it is (and it doesn't really matter anyway).

It sounds like your boss may be talking about extending the JSON Schema LIBRARY your using for some reason.
To be honest it's really difficult for me to understand the issues at play here now.


Cheers
Ben
Reply all
Reply to author
Forward
0 new messages