Issues in creating JSON document Type from JSON Schema

webMethods version: 10.5
Product: designer

I am trying to import a complex JSON schema in designer. I am trying to create JSON document type using JSON Schema. The creation completes successfully, but many fields and documents are created as type Object.

On investigating it further, I got to know it is an issue with only fields having type as "null"z

For example:

“years”: {
“type”: [
“integer”,
“null”
],
“title”: “xxxx”,
“description”: “xxxxx”,
“examples”: [
10
]
},

In above example, if I remove the type as “null” then field is getting created as proper integer field, but if I keep type as “integer” , “null” then field gets created as object.

You can use below samples. Sample 2 creates field middleName properly.

Sample 1:

{
“$id”: “https://example.com/person.schema.json”,
“$schema”: “http://json-schema.org/draft-07/schema#”,
“title”: “Person”,
“type”: “object”,
“properties”: {
“firstName”: {
“type”: “string”,
“description”: “The person’s first name.”
},
“lastName”: {
“type”: [
“string”,
“null”
],
“description”: “The person’s last name.”
},
“age”: {
“description”: “Age in years which must be equal to or greater than zero.”,
“type”: “integer”,
“minimum”: 0
}
}
}

Sample 2

{
“$id”: “https://example.com/person.schema.json”,
“$schema”: “http://json-schema.org/draft-07/schema#”,
“title”: “Person”,
“type”: “object”,
“properties”: {
“firstName”: {
“type”: “string”,
“description”: “The person’s first name.”
},
“lastName”: {
“type”: “string”,
“description”: “The person’s last name.”
},
“age”: {
“description”: “Age in years which must be equal to or greater than zero.”,
“type”: “integer”,
“minimum”: 0
}
}
}

Let me know if there is a way to import JSON schema properly.

Thank you.

It appears to be a limitation of the JSON schema import feature in webMethods. To overcome this issue, you can adjust the JSON schema structure by removing the ,
“null” part with a blank.

What is the plan for the use of the JSON schema? Is it just used to create the doc type?

Would creating an IS document type directly instead of from JSON schema provide the same value?

JSON schema in IS has a number of constraints. Not the least of which is it cannot be edited once created.

If you have an exhaustive example of the JSON to be used, you can use jsonStringToDocument to create a doc. Then copy/paste the resulting fields to a doc type.

Hello Ramakrishna,

I have changed the “type”: [ “string”, “null” ] to “type”: “string”
and I was able to create the json document type from schema successfully.
Thank you for the suggestion.

Hello Reamon,
Thank you for the response. You have made a good point.
Since it is a complex json, it is difficult for me to come up with exhaustive JSON sample to create document type.
I will explore some json data faker utility online to come up with dummy json.

I will keep this thread updated.

it appears that the problem lies with the JSON Schema definition using the “type” keyword for certain fields that can be of more than one data type, including “null.”

The behavior you observed is correct and expected according to the JSON Schema specifications. When you define a field with multiple types (e.g., “integer” and “null”), the JSON Schema indicates that the field can either be an “integer” or “null.” This results in the JSON document type being created as an “object” with the possibility of having either an “integer” value or a “null” value.

To resolve this issue and create the JSON document type properly, you can use the “oneOf” keyword in your JSON Schema. The “oneOf” keyword specifies an array of subschemas, and a given data instance must be valid against exactly one of these subschemas.

Here’s how you can modify your JSON Schema using “oneOf”:
{
“$id”: “example com/person.schema.json”,
“$schema”: “json-schema org/draft-07/schema#”,
“title”: “Person”,
“type”: “object”,
“properties”: {
“firstName”: {
“type”: “string”,
“description”: “The person’s first name.”
},
“lastName”: {
“oneOf”: [
{
“type”: “string”,
“description”: “The person’s last name.”
},
{
“type”: “null”
}
]
},
“age”: {
“description”: “Age in years which must be equal to or greater than zero.”,
“type”: “integer”,
“minimum”: 0
}
}
}

By using “oneOf” in the “lastName” property, you specify that the field can be either a “string” or “null.” This will ensure that the JSON document type is created correctly with the expected field types.

Remember to validate your JSON Schema using a JSON Schema validator after making the changes to ensure its correctness before using it in your application. If I made a mistake and couldn’t help you, you may want to seek help from experts in custom software development

1 Like

Good info. Is there a suggestion for how to address this when one does not own/control the JSON schema?

(My query is an academic one only to explore possibilities.)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.