Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Generate default JSON object from JSON schema #279

Closed
awag72 opened this issue Jul 22, 2020 · 3 comments
Closed

Generate default JSON object from JSON schema #279

awag72 opened this issue Jul 22, 2020 · 3 comments
Assignees
Labels
feature Something new.

Comments

@awag72
Copy link

awag72 commented Jul 22, 2020

Is it possible to generate a JSON object with default values from a JSON schema?

eg:
use schema:

{
    "title": "master data",
    "type": "object",
    "properties": {

        "Base": {
            "title": "base data",
            "type": "object",
            "options": {
                "collapsed": true
            },
            "properties": {
                "Value1": { "type": "number", "default": 1.1, "minimum": 0, "maximum": 1000, "title": "Value 1" },
                "Value2": { "type": "number", "default": 2.2, "minimum": 0, "maximum": 1000, "title": "Value 2" },
                "Value3": { "type": "number", "default": 3.3, "minimum": 0, "maximum": 1000, "title": "Value 3" }
			}
		}
	}
}

to produce valid JSON with default values:

{
	"Base": {
		"Value1": 1.1,
		"Value2": 2.2,
		"Value3": 3.3
	}
}

The actual schemas are more complex - also with array definitions and default array values - used for https://github.com/json-editor/json-editor
thx

@gregsdennis
Copy link
Owner

I looked at doing this (and generating a schema from a type) back when draft 6 was the latest. It gets really complex pretty quickly. It's the *Of and not keywords mostly that make things difficult.

I'll add this as a feature request, though, and have a look at it again.

@gregsdennis gregsdennis added the feature Something new. label Jul 22, 2020
@gregsdennis
Copy link
Owner

This also gave me an idea: #280.

@gregsdennis gregsdennis self-assigned this Jul 22, 2020
@gregsdennis
Copy link
Owner

Looks like this is a duplicate of #12.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Something new.
Projects
None yet
Development

No branches or pull requests

2 participants