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
1
vote
2 answers

CamelCase property names with NJsonSchema C# CodeGeneration

does anybody know a way to configure NJsonSchema to use CamelCase property naming durching code generation? I've a JSON schema with property names like message_id which lead to C# property name 'Message_id' where i.e. 'MessageId' whould be a more…
KwaXi
  • 123
  • 10
1
vote
0 answers

Generated constructor data

I am using NSwag to generate a typescript client for a backend API. Ultimately, it ends up generating a method: login(request: LoginRequest): Promise This is fine, however the problem is with the LoginRequest constructor. It generates…
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
1
vote
0 answers

NJsonSchema - how to add custom attribute to the c# generated class from json schema

I have a json schema as follows: { "properties": { "ArrayTypeProperty": { "type": "array", "items": { "$ref": "#/definitions/types" } } }, "definitions": { "types": { "properties": { "material": { …
Pooja Arya
  • 121
  • 1
  • 11
1
vote
2 answers

NJsonSchema C# - Change Generated Value Type

I am using NJsonSchema CsharpGenerator 10.1.24 and have the below schema I am using to generate a POCO: "description": "schema validating people and vehicles", "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", …
user2966445
  • 1,267
  • 16
  • 39
1
vote
1 answer

NJsonSchema - C# Code Generator Not Outputting Namespace

I have a series of JSON schema files that I'm trying to output to POCOs, and have the NJsonSchema.CodeGeneration.CSharp library loaded for this purpose. In specifying a namespace for the models, it does not appear that the namespace is actually…
theMayer
  • 15,456
  • 7
  • 58
  • 90
1
vote
1 answer

Resolve JSON $ref in unit tests using NJsonSchema

I have split my JSON schema into several files and reference them as required in the standard way ("$ref": http://rootpath/otherfile.json#/definitions/link). The JSON files are embedded resources within the project. The rootpath changes depending on…
B_D
  • 225
  • 2
  • 16
1
vote
1 answer

How to validate json with json schema in NJsonSchema c#

As part of contract tests I have to validate json response I got from rest-endpoint against json-schema present in a file. I'm using NJsonSchema and was not able to perform this. Json-schema in file is as something below { 'type':…
Dileep17
  • 299
  • 3
  • 18
1
vote
1 answer

NJsonSchema: JSON schemas with nested arrays generate incorrect C# types

I would like to use NJsonSchema to generate C# classes. The problem is that for nested arrays, the type ends up looking like…
nciao
  • 581
  • 4
  • 22
1
vote
2 answers

How do I force non-existent properties to null?

If I have a schema as follows: { "id": "http://example.com/my_application", "$schema": "http://json-schema.org/draft-04/schema#", "title": "my_application_schema", "additionalProperties": false, "definitions": { "NumberField": { …
Neil B
  • 113
  • 4
1
vote
1 answer

How to validate JSON Schema according to Draft v4 using JSON.NET Schema or NJSONSchema?

I have been looking into both JSON.NET Schema and NJsonSchema. Both don't seem to have any property / method that identifies if a JSON Schema is a valid one and in accordance with draft v4. Is it that only an exception will identify if a schema is…
Sana.91
  • 1,999
  • 4
  • 33
  • 52
1
vote
1 answer

Generate C# classes from json schema with heterogeneous array

I have a json schemas in a project and want to add build step to generate classes from them, on of these schemas contains an array of objects and strings, simplified example below: { "$schema": "http://json-schema.org/draft-04/schema#", …
Leo
  • 1,683
  • 2
  • 20
  • 25
1
vote
2 answers

Create json object from JsonSchema4

I have a complex Json Schema having properties and their definitions, I know the root property, Using jsonSchema4, how can I create the complete object for the root property that includes its nested dependencies as well.
1
vote
1 answer

Trying to retrieve LineNumber information from NJsonSchema ValidationErrors?

I need to do some json schema validation and am using NJsonSchema because I cannot get the license for Json.Net Schema. Is there a way to get LineNumber information for the ValidationErrors? It looks like the only properties available are // …
1
vote
2 answers

How to make sure that NJsonSchema only includes required fields?

I'm using NJsonSchema v2.6 for generating the JSON Schema for the following class: [DataContract(Name = "Message", Namespace = "")] public class AMessageModel { [DataMember] internal Guid MessageId { get; set; } internal DateTime…
MeTitus
  • 3,390
  • 2
  • 25
  • 49
0
votes
1 answer

How to parse true as boolean in json schema?

How can I parse the following schema using NJsonSchema? Is it valid to use "default": true? var problemJsonSchema = """ { "title": "JSONSchema", "default": {}, "oneOf": [{ "$ref": "#/definitions/JSONSchemaObject" …
Erik Z
  • 4,660
  • 6
  • 47
  • 74