Comments (4)
@puffyqi has this answered your question?
Thanks for your help. I have tried and is able to work.
How I do:
-
Get all the pointers from a JSON Schema file:
JsonNode schemanodes = JsonNode.Parse(schemadata); JsonPath jpath = JsonPath.Parse("$..[[email protected]=='date-time']"); PathResult pathresults = jpath.Evaluate(schemanodes); NodeList nodeslist = pathresults.Matches; for (int i = 0; i < nodeslist.Count; i++) { string pointer = nodeslist[i].Location.AsJsonPointer(); pointer_list.Add(pointer, new List<string>()); }
-
Get the pointers (instanceLocation) from Evaluation Results with the help of above pointers:
string schemalocationnode = node["schemaLocation"].ToString(); string instancelocationnode = node["instanceLocation"].ToString(); foreach (KeyValuePair<string, List<string>> entry in pointer_list) { string pointername = entry.Key; if (schemalocationnode.EndsWith(pointername)) { List<string> datapointerslist = pointer_list[pointername]; datapointerslist.Add(instancelocationnode); } }
-
Get the data values from datapointerslist (list of instancelocation) Using JPointer
foreach (KeyValuePair<string, List<string>> entry in pointer_list) { List<string> pointers = entry.Value; if (pointers.Count > 0) { foreach (string pointerlocation in pointers) { JsonPointer pointer = JsonPointer.Parse(pointerlocation); JsonElement? element = pointer.Evaluate(jsondatadoc.RootElement); if (element == null) { Console.WriteLine("cannot find pointer location: " + pointerlocation); } else { Console.WriteLine("data value: " + element.ToString()); Console.WriteLine("pointer: " + pointerlocation); } } } }
In Summary,
- Get all the pointers in a JSON schema file where it have the format "date-time"
- When verify schema file with data file, use the EvaluationResults and loop the details array. In details array, look for those "schemaLocation" that contains the pointers and save its "instanceLocation" in a list
- Convert JSON data file to JSONDocument and loop the "instanceLocation" list to get the data values from each pointer in the list
from json-everything.
I would use JSON Path.
You'll need to have the schema in JsonNode
form. Then use JsonPath.Net with the path $..[[email protected]=='date-time'].format
.
Each result contains the node and the JSON Path to it. Select the paths and you can convert them to pointer strings with the .AsJsonPointer()
extension.
from json-everything.
Oh! Also note that this won't catch format
keywords in the schema root. The ..
operation in JSON Path can't see the local node, only descendants.
from json-everything.
@puffyqi has this answered your question?
from json-everything.
Related Issues (20)
- Online schema validator: Is successful validation of illegal json just a quirk or intentional HOT 5
- System.MissingMethodException for IReadOnlyCollection<JsonNode> after updating from JsonSchema.Net.Generation 4.3.0 to 4.3.0.2 HOT 5
- Can't get DiscriminatorKeyword working HOT 2
- Schema Evaluation fails with "Cannot resolve schema at {uri}" HOT 5
- Could not load file or assembly 'JsonPointer.Net, Version=5.0.0.0, Culture=neutral, PublicKeyToken=17ed63f672b0e278'. The system cannot find the file specified. HOT 10
- IndexOutOfRangeException occurred when evaluating schema with parallel execution. HOT 1
- jsonnet as sister of json-e HOT 3
- Escaping single quote in json path string HOT 8
- Extract data annotation attributes from JsonSchema.Net.Generation into separate project HOT 2
- Is there a way to do JSON validation that does case insensitive matching on property names? HOT 8
- Support language packs in schema playground
- sileo-featured.json
- How to export or save JsonSchema to plaintext? HOT 4
- How to write a JsonSchemaBuilder for a class that has a property of a class? HOT 4
- Schema generation doesn't work on site HOT 1
- maximum/minimum use decimal which do not parse certain many double "number" strings HOT 3
- `Json.Schema.JsonSchema.Evaluate` throws "`System.OverflowException`: Value was either too large or too small for a Decimal." HOT 4
- Get json data from only required properties based on the attributes set HOT 4
- Schema validation crashes with stack overflow HOT 12
- Patch Path Not Escaping Forward Slash HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-everything.