@extendscript/aes.patch.json.instantiate

Adds `instantiate()` to JSON. A simple tool for instantiating JSON Schemas.

Usage no npm install needed!

<script type="module">
  import extendscriptAesPatchJsonInstantiate from 'https://cdn.skypack.dev/@extendscript/aes.patch.json.instantiate';
</script>

README

json.instantiate

version

Extension

Adds instantiate() to JSON. A simple tool for instantiating JSON Schemas.

Source: tomarad/JSON-Schema-Instantiator

Install

npm install @extendscript/aes.patch.json.instantiate

Include

#include 'node_modules/@extendscript/aes.patch.json.instantiate/instantiate.js'

Use

var schema = {
    "type": "object",
    "properties": {
        "title": {
            "type": "string",
            "default": "Example"
        },
        "description": {
            "type": "string"
        }
    },
    "required": ["title"]
};

instance = JSON.instantiate(schema);
// instance === { title: "Example", description: "" }

instance = JSON.instantiate(schema, {requiredPropertiesOnly: false});
// instance === { title: "Example", description: "" }

instance = JSON.instantiate(schema, {requiredPropertiesOnly: true});
// instance === { title: "Example" }

Test

You can test the code against a range of targets:

npm run test target-1 target-2

We keep a log of test results