0

I receive flattened json properties in the following format:

jsonName.propertyPath1.propertyPath2..., value

Example:

UniversityCollection.Persons.Person1.Name, Dave

I need to validate these kind of properties with a JSchema, that a receive from a file before generating a JObject with all the properties. I just have the program that collect them and generate the JObject.

It is important to note that i do not have knowledge about neither the structure of the Json nor the Json schema. I want to make a general program that validates any Json received through its associated Json schema.

dbc
  • 104,963
  • 20
  • 228
  • 340
  • 1
    You could "unflatten" the path/value pairs into a `JToken` hierarchy, then validate that. See the answer to [How to unflatten flattened json in C#](https://stackoverflow.com/q/40541842/3744182) by [Danny Su](https://stackoverflow.com/users/1311686/danny-su). – dbc Sep 24 '21 at 18:37
  • *i do not have knowledge about neither the structure of the Json **nor the Json schema.** I want to make a general program that validates any Json received through its associated Json schema.* -- what do you mean by this? If you don't know the schema how can you validate using it? – dbc Sep 24 '21 at 18:41
  • If you have a Json.NET Schema `JSchema` and a Json.NET `JObject`, you can validate the object against the schema using [`SchemaExtensions.IsValid(JToken, JSchema)`](https://www.newtonsoft.com/jsonschema/help/html/M_Newtonsoft_Json_Schema_SchemaExtensions_IsValid.htm). See the documentation page [Validating JSON](https://www.newtonsoft.com/jsonschema/help/html/ValidatingJson.htm). Is that all you are looking for? If not, can you please clarify your problem? – dbc Sep 24 '21 at 18:43

0 Answers0