Meta Box Lite
Meta Box

How JSON Schema Autocomplete Simplifies Field Group Creation in Meta Box

As we worked more with code editors, we realized that writing JSON files for field groups gave us more flexibility and control. But doing it manually? That often meant typos, missing commas, and lots of time switching between tabs to check the documentation.

That’s why autocomplete powered by JSON Schema steps in, making your workflow smoother, faster, and far less error-prone.

JSON Schema autocomplete suggests options as you type.) Video Version
Video Version

What is JSON Schema Autocomplete?

JSON Schema is a standard for defining the structure and expected values of JSON data. It describes what properties are allowed, their data types, whether they’re required, and other constraints.

When you link your JSON file to a JSON Schema, you unlock a powerful autocomplete feature that allows smart editors like VS Code understand the structure of your data and help you write JSON more quickly and accurately, all while offering real-time feedback on your code.

Particularly:

  • Autocomplete suggestions for properties: Smart editors will suggest properties such as "id", "type", "name", etc.
  • Contextual options for each property: For example, when defining "type" for a field, it suggests field types supported by Meta Box, such as "text", "number", "datetime", and more.
  • Error detection: The editor will flag errors if incorrect data types are used or required properties are missing.

Why Use JSON Schema Autocomplete?

JSON Schema autocomplete is more than just a time-saver. It helps you:

  • No need to memorize fields: Just type a quotation mark ("") and the editor will instantly show a list of valid options.
  • Avoid typos and syntax errors: If you type something wrong, forget a comma, or miss a required property, the editor will flag it immediately.
  • Write faster: No more switching tabs to check documentation; everything is right there in your editor.

In fact, Meta Box has already provided official JSON Schemas for field groups, relationships, and setting pages. This is not commonly found in other custom field plugins, making Meta Box stand out.

Besides, once you create the field group in the JSON file, simply sync it to the database using the local JSON feature, and then your field group will be set up with the fields and settings you need.

Experience JSON Schema Autocomplete in Action

To use the JSON Schema Autocomplete feature, you only need to include a $schema reference at the top of your .json file. Then, the editor will then understand the expected structure, like I mentioned earlier, start suggesting keys, and even highlight errors as you go.

Let’s walk through how to set this up, with an example of a field group for page settings with two fields:

  • A Radio field to choose the sidebar position (left or right).
  • A Switch field to toggle the sticky header.

Start by creating a file named mb.json manually. This is where you'll define your field group and fields using JSON.

Create a mb.json file manually.

Next, include a special line at the top to reference the Meta Box JSON schema:

"$schema": "https://schemas.metabox.io/field-group.json"

Include a $schema reference at the top of your mb.json file.

This line tells the editor to use the Meta Box JSON Schema for autocomplete and validation.

If you're creating a relationship or settings page, you can easily reference the corresponding schema link since Meta Box has already written schemas for them here.

Now, you'll see how helpful it can be!

Once you want to add some basic information like title, id, and post types, autocomplete suggests options as you type by listing them in a dropdown.

Autocomplete suggests options as you type by listing them in a dropdown.

Moving to create the fields!

As soon as you define fields inside the fields array, autocomplete also works there, helping you choose the correct field type, available options, and more.

Create fields with autocomplete.

Even better, if anything is missing or incorrectly formatted, the editor will alert you immediately.

Get warnings if anything is missing or invalid.

Sync JSON File to Load Field Groups

After saving, your JSON file is ready and saved in the correct folder (usually /mb-json/ in your theme), head to the Meta Box > Custom Fields.

If the file is valid, you’ll see it listed with a Sync available status. Just click Sync, and your field group will be ready to use, exactly as you defined it.

Just click Sync, and your field group will be ready to use.

You can also click Review to preview the configuration before syncing, in case you want to check for any errors.

Once synced, you’ll see the field group with the same configuration as we created in the JSON file.

The field group with the same configuration as we created in the json file.

If you're curious how this fits into the bigger picture, check out how Meta Box works with Local JSON and registering blocks via JSON. These approaches all share the same goal: bringing more control, reusability, and clarity to your workflow.

Final Words

Using schema-based JSON autocomplete in Meta Box is a great way to boost productivity. If you're someone who prefers working directly with code, this feature gives you the best of both worlds: precision and convenience. Hopefully, it’ll make your workflow not just easier, but also a lot more enjoyable.

By the way, JSON Schema isn’t just for humans; it also powers AI tools like ChatGPT or Cursor to generate field groups from a simple prompt. See how Meta Box makes custom fields with AI easier than ever.

Leave a Reply

Your email address will not be published. Required fields are marked *