Find keyword in JSON-Object & Spelling checker using C#

Sela 126 Reputation points
2022-02-03T09:28:39.847+00:00

Dear Sir or Madam,
I have a question about finding the keywords in Json object after reading the file (I read the file like this:

            string path = @"path";
            var JObject = JsonConvert.DeserializeObject(File.ReadAllText(path));
            Console.WriteLine(JObject);).

I would like to solve this with try and catch to check if the keywords exist and also I would like to check the spelling of the keywords after checking the keywords for "is there or not". I have already created the required classes for it (the class looks like this:

        public class Driver
        {
        public string type;
        public int speed;
        public string label;
        public string name;
        public int id;
        public string startpoint;
        public string midPoint;
        public string endpoint;
        }

--> For example I want to find the keyword Speed in the json object and then I want to make sure that the keyword does not have any misspellings like Sped instead of Speed.

Do you have an idea how I can do this best. Thanks in advance.

With kind regards,
Sela

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,364 questions
{count} votes

3 additional answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2022-02-03T11:04:01.137+00:00

    It is probably easier to look in json in file instead of looking in object for key word

             string path = @"path";
             string json = File.ReadAllText(path);
             bool hasKeyWord = json.Contains("MyKeyWord");
    

    var JObject = JsonConvert.DeserializeObject(json);

    0 comments No comments

  2. P a u l 10,406 Reputation points
    2022-02-03T22:15:09.29+00:00

    You could do something like this if you want to let the framework parse the JSON for you & you just need to check the properties:

    https://pastebin.com/YMDuGc0W

    (forum blocked posting)

    0 comments No comments

  3. Bruce (SqlWork.com) 57,731 Reputation points
    2022-02-03T22:41:40.92+00:00

    as you are using newtonsoft. you could just use the standard json schema validation support rather than trying to roll your own:

    https://www.newtonsoft.com/jsonschema

    0 comments No comments