The use case
When processing files, I often face the issue that I validate a file and want to return a list of validation errors pointing to the location of the errors. Depending on the context this can work better or worse, also depending on the audience of the error (e.g. an Excel sheet, the user would like to be pointed to row and column of his errors, maybe optional the sheet name). When it gets more technical, things become harder to parse and describe. For XML there is in theory XPath, for JSON there is JsonPath, but building a correct expression is pretty hard depending on your layer of validation. But things get really messy if you nest them, e.g. a JSON value containing a csv or vice versa.
The question
I was wondering if there is a standard to describe such file error locations? If not, is there any interest in defining one?
So far I was thinking about some kind of meta-schema that can also make use of existing standards. The schema must be machine-readable and should be human-readable (on a best effort basis).
Basic ideas / examples:
In general we need an identifier for a sub-schema that can follow it's own syntax. The syntax may have optional components.
- regular text blocks:
@text#L5#C:26refering to line 5, character 26@text#L5:C26-35refering to line 5, character 26-35@text#L5-7refering to line 5-7
- CSV:
@csv#L5:C3refering to line 5, column 3 - Excel files:
@xslx#!sheet1:L3:C5refering to line 3, column 5 in sheet1 - XML:
@xml#/movies[3]/producer–> using XPath syntax to point to an element (or rather a basic subset of XPath) - JSON:
@json#$.movies.[3].producer–> using JsonPath syntax to point to an element (or rather a basic subset of JsonPath)
More formats could be added as required over time.
Nested references
Now the tricky part begins when nesting them. JSON in XML, XML in JSON, JSON in CSV… Regular multiline text in JSON… there is an infinite amount of combinations.
The idea here would be to reference the location top to bottom (or rather outside-in?). Now if I have a CSV where column 5 contains JSON and the JSON field "foo" has a constraint.
The idea would be to express this such as: @csv#L5C3[@json#$.foo]
I guess the control characters need some more thought to not clash with e.g. XPath or JsonPath.
So hopefully someone can point me to an existing solution, as it is probably more complex than my 20 minutes thinking about it revealed.
submitted by /u/Brutus5000
[link] [comments]
from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/MSbdocy