JSON Forms Extended

Example: additional properties

Example ID: additional-properties
Demo entry: Spec: Additional properties (#spec-additional-properties)
Domain: inventory metadata
Specs covered:

Five objects whose keys are data rather than schema, plus an object combining static fields and dynamic properties. The point of the example is that a key is a value too: what it may be called, whether it can be reached by a data path, and whether it can be renamed or deleted are all separate questions, and they have different answers.

Files

File Role
schema.json Five dynamic-property objects: free-form, propertyNames-constrained, patternProperties with additionalProperties: false, imported keys, and one with minProperties.
uischema.json allowEmptyPropertyNames on one control and explicitly false on another, over a global true.
data.json Keys that used to be impossible: brackets, digits, an empty name, surrounding whitespace, a dot and a slash. One key violates its propertyNames.
config.json showUnfocusedDescription, restrict, and a global allowEmptyPropertyNames: true, all top level.
translations.json English and Bulgarian, including the three name-refusal messages.

No uischemas.json: nothing here needs a registered detail form.

What the form contains

Inventory metadata
  Inventory labels      allowEmptyPropertyNames: true   -> 5 keys, incl. "" and "  spaced  "
  Telemetry readings   propertyNames: pattern+minLength -> "sensor-x" is too short  (invalid)
  Supplier headers      additionalProperties: false      -> only x-supplier- / x-trace-
  ---
  Imported annotations free-form                        -> "legacy.key", "notes/1"
  ---
  Required quota       minProperties: 2, option false   -> Delete disabled under restrict

Validation state

Validated with Ajv (allErrors, strict: false), the supplied data produces two errors — both from one violation:

Instance path Keyword Message
/telemetry minLength must NOT have fewer than 9 characters
/telemetry propertyNames property name must be valid

sensor-x is eight characters and propertyNames requires nine. Ajv reports the inner failure and the wrapping keyword separately, which is why one bad key produces two entries. The key stays visible and editable — §19 — and renaming it to something nine characters or longer clears both.

Note that the errors are attached to /telemetry, the object, not to a path for the offending key. A key has no data path of its own, so there is nowhere else to put them.

Expected behaviour

What a key may be called

Inventory labels already holds keys that used to be rejected. items[0] is one key, not an index into an array. 2024 is an object key, not an array position. Both work because core 3.9 stopped using lodash's path grammar in the reducer; before that they were written to the wrong place. See 14.

Type sdf.sdf into any Add box. It is accepted, and it becomes one key called sdf.sdf — not a nested { "sdf": { "sdf": … } }. A dot cannot be addressed by a data path, but that is a reason to edit the property differently, not a reason to refuse it: the value gets a form of its own, exactly as the empty-named one does.

spaced keeps its spaces. Names are stored exactly as typed; trimming is only used to decide whether a name counts as blank. Add a property called two and read the Data tab.

Empty names

Inventory labels permits an empty key, and one is already there. Its label is visually blank — not the literal "" — and Rename and Delete still sit above its value, exactly like every other property.

Edit the empty-named property's value. It works, and the object around it is untouched. This is not an ordinary delegated control: an empty path segment composes away to the parent's own path, so a control dispatched there would edit the whole labels object. It is edited in an isolated form rooted at that value instead, and written back under its exact key. The same applies to legacy.key in Imported annotations.

That isolated form has its own root schema, so a local $ref inside the property's schema would stop resolving. The schema is rebundled for it: the original document travels along under definitions.__jsonforms_root and local references are rewritten to point into it. Nothing in this example needs it, but a schema with shared definitions would.

Clear the Add-property name box and look for an error. There is none, even though an empty key already exists and adding a second would collide. the renderer contract: an exactly empty draft "must not show inline name-validation errors on initial load or after it is cleared or reset". The Add button is still disabled, because suppressing the message must not suppress the judgement.

Required quota has the option explicitly off, over a global true in config.json. Its Add button stays disabled on an empty name. the renderer contract requires an element option to override config "including false overriding true", which a truthiness merge would silently get wrong.

Use the demo's own switch to see both halves. The settings panel carries Allow Empty Property Names, which writes the global config option. It reads as on when this example loads, because the example's config.json sets it; turn it off and Inventory labels stops accepting an empty name while Required quota is unaffected either way — the control's own option has the last word.

What the schema admits

Telemetry applies the whole of propertyNames. Try sensor-a: refused, because it is eight characters and minLength is nine. sensor-deck-b is accepted. A pattern-only check would have taken both.

Supplier headers admits only what its patterns claim. additionalProperties is false, so a name must match ^x-supplier- or ^x-trace-; x-other-id is refused.

Type __proto__ into an Add box. It is accepted and becomes an ordinary own property; the containing object's prototype is untouched. It is not in the fixture, and that is itself worth knowing: a quoted __proto__ survives JSON.parse, but the bundler compiles a JSON module into an object literal, where {"__proto__": v} sets the prototype rather than creating a key — so the property would silently vanish from the example before the form ever saw it.

Imported annotations holds notes/1. A slash is an ordinary character in a key; it only needs escaping when a JSON Pointer is built from it, not when the key is stored.

Removal

Required quota has two entries and minProperties: 2 with restrict on, so both Delete buttons are disabled. Switch restrict off in the Config tab and they become available, with the validator reporting the shortfall instead.

Localization

Switch the demo to Bulgarian. The section heading, the placeholder, the Add/Rename/Delete names and all three refusal messages translate. The keys themselves do not: they are data.

Fallback behaviour

Situation Result
No allowEmptyPropertyNames anywhere Empty and whitespace-only names are refused.
Config true, element absent Permitted — config supplies the default.
Config true, element false Refused. The explicit element option wins.
A name containing . Accepted, and edited through an isolated form. It is one key, not a nested path.
An empty or dotted key, however it arrived Kept, shown, and editable through an isolated form; renaming and deleting work normally.
propertyNames present Applied in full. It does not imply allowEmptyPropertyNames.
No validator available to the control Only the pattern constraints are checked — a documented reduction, not a skip.
additionalProperties: false with no patternProperties No name is admissible; Add stays disabled.

Conformance scope

This walkthrough describes the portable contract. Renderer support must be checked by a host adapter; the package validates the authored assets, not live UI behavior.

Standalone host setup

Load the JSON assets listed in the catalog into a host with the relevant renderer capabilities. No framework registration module is required by this package.

Feature navigation

Explore one feature at a time using the tabs: Dynamic properties, Imported keys, Option overrides. Tab titles are localized in English and Bulgarian. The tabs share the existing form data.

Static and dynamic properties

The Static and dynamic properties tab shows Inventory details with schema-defined Reference and Quantity fields, followed by editable Warehouse and Handling keys in Additional Properties. Both sections belong inside the same object boundary. Static fields must not appear again in the dynamic list.

Proposed acceptance cases for clearing values

In a host using the real renderer registry, load an object with an additional string property whose schema defines a nonempty default. Activate the field clear button, then repeat by deleting all text. Verify that the exact key has the empty string value, its editor stays mounted, and the user can enter a new value. Verify that explicit Delete removes the key and row. Repeat with an empty key and a dotted key through the host's literal-key editor.

For an additional property containing an object with a declared string field, clear that nested field and verify its normal absence semantics while its additional-property parent and row remain present. These are proposed host acceptance cases, not executable tests in this specification package.