Questions tagged [njsonschema]

A .Net library for validating JSON against a schema or generating a schema from an existing .Net class.

The library can read a schema from a file or string and validate JSON data against it. A schema can also be generated from an existing .NET class. With the code generation APIs you can generate C# and TypeScript classes or interfaces from a schema.

http://NJsonSchema.org

59 questions
0
votes
0 answers

Generate a JsonSchema from a c# class including conditional member setters logic

I Have the following Class Class Creature { public string Name {get; set;} private string _clss; public string Clss { get {return _clss} set { …
maces13
  • 305
  • 3
  • 13
0
votes
0 answers

How to perform Case Insensitive validation with NJsonSchema for Enums

I am using NJsonSchema to validate a Json against a JsonSchema. Here is the code snippet. My current code is case-sensitive and validates only RED, and BLUE for enum color. I want to validate the JObject(JSON) case-insensitively against the Enum…
SyncMaster
  • 9,754
  • 34
  • 94
  • 137
0
votes
2 answers

How to validate json schema without using Newtonsoft.Json.Schema in c# Web API

I have json schema and value to compare against it. I have implemented it using Newtonsoft.Json.Schema. But now realised that it is not for free use. I then tried to implement is using NJsonScehma nuget package but now getting the below error on…
0
votes
0 answers

How can I retain lower camel case properties while using Json SerializerSettings?

I'm trying to setup JSON validation using NJsonSchema. I want that C# class properties are translated to lower camel case when validated. I managed to achieve that goal by passing a custom JsonSchemaGeneratorSettings object to…
Daniel
  • 3,092
  • 3
  • 32
  • 49
0
votes
0 answers

generate minimum model from json to c# using NJsonSchema

I'm using NJsonSchema to generate a C# model from a json sample. Environment: dotnet6 I's working fine but it is generate lots of comments and properties that I don't want. I need a solution either with NJsonSchema or any other library. Here is an…
CloudAnywhere
  • 669
  • 1
  • 11
  • 27
0
votes
0 answers

Error on using NJsonSchema JsonSchema.FromSampleJson with objects array

I need to get a Json Schema from a Json data string, and inside that string I have an array of another object. I am trying to use JsonSchema.FromSampleJson, with the code var schema = JsonSchema.FromSampleJson(Json); var schemaJson =…
Elvis
  • 1
  • 1
0
votes
0 answers

NJsonSchema C# - Remove $ref fields and replace by the actual structure

I'm using NJsonSchema to convert a normal Json to Schema. However, NJsonSchema returns the Schema with $ref fields, but I want to have the actual structure. For example: { "$schema": "http://json-schema.org/draft-04/schema#", "type":…
0
votes
0 answers

Dealing with external namespaces for a POCO data model implemented through NJsonSchema auto-generated classes

In a dotnet microservice architecture, to avoid exposing my data model and its logic, I am willing to add a POCO data model layer following a mechanism: fullDataModel>json>pocoDataModel. Here is my reduced fullDataModel public class MyDto { …
Gipe
  • 1
  • 1
0
votes
0 answers

map json schema to c# model with NJsonSchema throws System.InvalidCastException

Im trying to convert really simple json schema to my c# model using nuget from this link Im using example code from the github repo such as: var schema =…
Stefan0309
  • 1,602
  • 5
  • 23
  • 61
0
votes
0 answers

NJsonSchema CSharp Code Generator when json schema contains references to other local json schema files - change name of referenced external class

My application generates C# classes from json schema files, using the NJSonSchema library and the included CSharpGenerator. The main json schema file contains a reference to a local secondary json schema file, available in the same directory. The…
Abra Sat
  • 11
  • 2
0
votes
0 answers

Swagger Generation using OneOf for Inheritance

I am trying to use NSwag to generate a swagger document for my REST API. My response object contains a property that is an abstract class. I would like the schema to use oneOf for the child classes instead. For example my current output looks like…
SA3709
  • 192
  • 2
  • 11
0
votes
1 answer

Generate JsonSchema from a class hierarchy in C#

I have a class hierarchy that I want to serialize to json in a tagged union in an array. class BaseComponent { public string Id { get; set; } } class Child1: BaseComponent { public string Child1Prop { get; set; } } class Child2:…
ivarne
  • 3,753
  • 1
  • 27
  • 31
0
votes
0 answers

Reuse single reference schema with multiple validation restrictions

I have one schema which I want to use for 2 properties: { "title": "testschema", "type": "object", "additionalProperties": false, "required": [ "prop2" ], "properties": { …
tv31
  • 31
  • 3
0
votes
2 answers

NjsonSchema Validation If Property1 is equal to Something then require Property2

I seem to not be able to get const or enum working as part of an if-then-else JSON schema validation. They seem to be interchangeable when 1 validation value is concerned. (Reference) Here is my JSON schema { "$schema":…
Artexias
  • 195
  • 2
  • 14
0
votes
1 answer

Convert json schema to a c# poco without attributes

I'm looking to convert a simple json schema into a c# poco. { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Test_Schema", "description": "A schema for validating a test object", "type": "object", "additionalProperties":…
Artexias
  • 195
  • 2
  • 14