Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft.Json.Schema.JsonSchema is obsolete?

I'm trying to create a method to validate a Json string with a Json schema using this method: http://www.newtonsoft.com/json/help/html/JsonSchema.htm

It says the object is obsolete and moved to its own package, so I use NuGet and install the package (Newtonsoft.Json.dll and Newtonsoft.Json.Schema.dll are references) and have:

using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Linq;

    public bool validateSchema(string _Json)
    {
        JsonSchema schema = JsonSchema.Parse(
                        @"{
                            'properties': {
                                [MySchemaHere]
                        }
                        ");
        JObject jobject = JObject.Parse(_Json);

        return jobject.IsValid(schema);
    }

How do I get rid of the obsolete message? It sounds to me like the code has been moved to the other package/dll, but is called/used in the same way and I'm somehow referencing the obsolete one? This seems like I'm missing something simple/obvious.

EDIT: Here's an image that might help.

http://i.imgur.com/PWwpGRx.png

like image 477
William YK Avatar asked Feb 09 '16 17:02

William YK


People also ask

Is Newtonsoft JSON obsolete?

Yet Newtonsoft. Json was basically scrapped by Microsoft with the coming of . NET Core 3.0 in favor of its newer offering designed for better performance, System. Text.

How do I check if a JSON Schema is valid?

The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then use the IsValid(JToken, JsonSchema) method with the JSON Schema. To get validation error messages, use the IsValid(JToken, JsonSchema, IList<String> ) or Validate(JToken, JsonSchema, ValidationEventHandler) overloads.

How do you validate a schema in Rest assured?

Once we launch this application, we shall get a field called the Sample JSON Document. Here, we have to add the JSON body whose scheme we want to validate. Then click on the Generate Schema button. Then the corresponding scheme for the JSON gets generated at the bottom of the page.

Is JSON net schema free?

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, see http://www.gnu.org/licenses/agpl-3.0.html.


3 Answers

I finally just created a new project and copied/pasted their example and I see my painfully obvious mistake that I've been fighting with.

I should be using:

JSchema

and not

JsonSchema

like image 53
William YK Avatar answered Oct 24 '22 09:10

William YK


My problem got resolved when I added a new NuGet Package after searching for "JSON.net schema", which resulted in showing another Newtonsoft.Json.Schema Package in option:

Tools > Nuget Package Manager > Manage Nuget Packages for Solution

enter image description here

After doing this, change JSONSchema object to JSchema object. This will remove the obsolete message and compile the code properly as well.

after:

string schemaJson = @"{
  'description': 'A person',
  'type': 'object',
  'properties':
  {
    'name': {'type':'string'},
    'hobbies': {
      'type': 'array',
      'items': {'type':'string'}
    }
  }
}";

change:

            JsonSchema schema = JsonSchema.Parse(schemaJson); 

to

            JSchema schema = JSchema.Parse(schemaJson); 
like image 27
Ganesh Kamath - 'Code Frenzy' Avatar answered Oct 24 '22 08:10

Ganesh Kamath - 'Code Frenzy'


Are you sure that you have this dll? ,your problem seems to be this JSON Schema validation has been moved to its own package, check more info here:

http://www.newtonsoft.com/json/help/html/N_Newtonsoft_Json_Schema.htm

Hope this help

like image 36
우두머리 Avatar answered Oct 24 '22 09:10

우두머리