networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
797 stars 320 forks source link

How to generate the json structure acording to the schema? #1085

Open beclever opened 2 days ago

beclever commented 2 days ago

for example, given json schema: { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "http://example.com", "title": "ExampleBasicApp", "description": "desc", "type": "object", "properties": { "id": { "description": "Subscription Id", "maxLength": 512, "type": "string" }, "spsid": { "description": "Service Provider Subscription Id", "maxLength": 384, "type": "string" }, generate a json like below: { "id": "string", "spsid": "string" }

justin-tay commented 2 days ago

This library isn't really intended for that use case but you can attempt to do so using a walker.

https://github.com/networknt/json-schema-validator/blob/3234d023706d04fe8ad58e616b23f482beb2579d/src/test/java/com/networknt/schema/walk/JsonSchemaWalkListenerTest.java#L566-L621

beclever commented 18 hours ago

Thank you, this is really helpful to me.