I have following scenario of incoming messages from different devices to processing unit which shall process the messages based on message type.
Messages with following Schema definition for
hobbies, sayschema-hobbiesJSchema hobbiesSchema = JSchema.Parse(@"{ 'type': 'object', 'properties': { 'name': {'type':'string'}, 'hobbies': { 'type': 'array', 'items': {'type':'string'} }}}");Messages with following Schema definition for
countries, sayschema-countriesJSchema countriesSchema = JSchema.Parse(@"{ 'type': 'object', 'properties': { 'name': {'type':'string'}, 'countries': { 'type': 'array', 'items': {'type':'string'} }}}");Messages which do not follow any of above
Schemadefinitions
Now, I am able to validate the hobbies messages as follow
    JObject hobbies = JObject.Parse(@"{
    'name': 'James',
    'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
    }");
    IList<string> errorMessages;
    bool valid = hobbies.IsValid(hobbiesSchema , out errorMessages);
    Console.WriteLine(valid);
I shall able to merge both schema and validate different incoming messages. How can I do that?
For example:
If message Json is,
    {
    'name': 'James',
    'hobbies': ['.NET', 'Blogging', 'Reading', 'Xbox', 'LOLCATS']
    }
Output shall be: True
If message Json is,
    {
    'name': 'James',
    'countries': ['India', 'Australia']
    }
Output shall be: True
If message Json is,
    {
    'Time': '03:45 AM',
    'heartbeats': ['30', '45']
    }
Output shall be: False
Note:
- Sample schema used in this question is just for reference. Real schema is very complex.