Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Moin,

There is a Json file and an associated object.
I will now check this object professionally, whether the data makes sense.
If this is not the case, I would like to know the corresponding line number in the Json file to make it a little easier for the user.
I don't find an approach to solve this issue.
I use the Newtownsoft library.

CU
Carsten

What I have tried:

Nothing because no ideas :(
Even Google is not hapefully
Posted
Updated 1-Aug-20 5:38am
Comments
[no name] 1-Aug-20 11:30am    
Quote: "I will now check this object professionally, whether the data makes sense."
What are the rules to qualify the json to make sense or not?

Keep in mind: A valid json does not mean the data make sense...
Carsten Giesen 2-Aug-20 4:38am    
This is a pice of code. Given by the devoloper.
Example:
Value1 could be "monday", "sunday", "fryday" if Value2 is "hot"
Value1 could be "beer", "wine", "whater" if Value2 is "warm"
BillWoodruff 2-Aug-20 1:04am    
If you create the Json, then the solution is to check the data before transforming your object graph; if you have no control over the Json, then you either read into an object graph, edit that, and rewrite ... or you implement some kind of rule engine that operates directly on Json.
Carsten Giesen 2-Aug-20 4:40am    
Actual now chance. I get a JSON text only. Perhaps in future I will have a wizard. But today I have to do it this way :(
BillWoodruff 2-Aug-20 4:50am    
Then, the issue is whether or not the Json has a predictable structure: a structure you understand, and can parse.

1 solution

To that that, you;re really going to want a schema to run the JSON against. Try starting here: Validating JSON with JSON Schema[^] and see what you can find.
 
Share this answer
 
Comments
Carsten Giesen 1-Aug-20 15:17pm    
Thanks for this tip. Thats new for me. But that's only give me the structure or the types validation.
What I have to validate ist more complex.
Example: If Property 1 is "Monday" than Property 2 can only be "Pizza", "Fish" or "Rice"
If it's "Sunday" then "Bier", "Wine", "Gin"

I hope it's a lite bit clear now. My english is realy bad ;)

In this case I like to find the property 2 and mark the line.

This prpoerty is include in an object, and I have a list of this objects.
So I have property 2 more than one in my text file.

Carstne
OriginalGriff 2-Aug-20 1:54am    
There is nothing that will do that for you: you will have to (as Bill says) implement a rules engine that processes the JSON data and checks it yourself.
And that is going to be a fair amount of work!
Carsten Giesen 2-Aug-20 4:36am    
I have a running rule engine! I like to inform the user, in witch row the error is.
I didn't find a way to indetifiy the text row based on my object
OriginalGriff 2-Aug-20 5:06am    
If your engine is processing the JSON, then just keep a line count!
If it isn't, then you would need to find a way to correlate the data being processed by the rules engine with the original input - and since we have no access to your code (or even a vague idea what the data the engine is processing looks like or how it is generated from the original JSON) we really can't help you do that!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900