This tool from CapeSoft may help you. It doesn’t check if the fields are complete, but if you have the JSON/XML at hand, it can create the structure based on the file and should not left fields out.
As far as the order for the files, at least in my experience that is not as important as having the correct names (and case) defined in the schemas.
Thanks for the response.
My system already creates the JSON/XML correctly and imports it correctly.
However sometimes the users does not supply their files in 100% the correct format and field names and then everything breaks.
That is why I am trying to get a solution to verify the JSON/XML files before loading and processing them.
Very true. That’s usually the main problem with API calls.
Another tool I use to check the responses is Postman, but requires an extra job from my side if no WSDL is provided. What that I can see the raw responses and validate fields. But is not an automated process.
So let’s kill the easy one first. Fields in JSON and XML have no “order”. There is no such thing as correct, or incorrect, order because the fields themselves are not ordered. In other words creators, and parsers, are free to construct the structure in any order they like.
I’ll use “json” to refer to “xml and json” here…
Generally speaking the “matching” of fields in the json to your structure are not “1 to 1”. In other words the json is allowed to contain extra fields (they are ignored on input) and they are allowed to not include some values (the receiver then supplying reasonable defaults.
Bear in mind that the json is nested, and contains “lists”, so each node in the tree can contain a bunch of fields, which may in turn be a different bunch to the next sibling mode. You are suggesting that each node, through the whole file, be checked against some valid list of fields for that node, both to detect items you don’t recognise or to complain when a node is “insufficiently populated”.
both jFiles and xFiles (xFilesTree class) have a AssignMissingField method. When loading the clarion structure from the json, if a field is not found the AssignMissingField is called. You can supply a default here or generate an error.
To determine if there are “extra fields” you would need to walk the tree (using the supplied GET methods) checking each node to see if you like the name.
Yeah, the beauty of JSON is that the structure is whatever you get and it can contain, or not contain, anything, in any order.
Makes validation interesting but if you have fields that you consider “required” then you have to verify both the existence of the field name and the data passed.
It’s up to you what you do about unexpected fields, you can either ignore them, or warn the poster that the data is not correct, similar to the way Clarion tells you that you’ve misspelled a field name when building - which is probably the best option for identifying typos.