Convert all XML artifacts to JSON

I have come to the conclusion that we need to convert Moqui to a JSON-centric platform or die on the vine. The main reason for doing this is to make it AI friendly. I have spent the last couple of months investigating how difficult it would be to go from a natural language requirements specification to a working Moqui app. I focused almost entirely on the UI aspects of this task. I got to the point that I had the server generate JSON UI data and it was sent to the client which quickly converted it to Vue/Quasar macros - which is pretty much in line with what Moqui 4.0 is doing (except the JSON part).

When I started looking into the “natural language to a working app” task, I figured it would have to start with a markdown description of what is desired. Then, in order to keep the context window as small as possible, I had AI convert the description to Groovy DSL which matched the Moqui screen macro - like form-single, form-list, etc (but I added a bunch of new macros). Then I would validate the Groovy DSL and convert it to a screen XML file. Then the runtime would convert the XML to JSON and send it to the client to be rendered. That is a lot of conversions.

The obvious evolution was to make the “source of truth” to be JSON. There is some validation to do, but, basically I could just send the screen definition file directly to the browser and have it converted there. I think that is just the beginning of the advantages to using JSON.

The big advantage is the ease with which Moqui can interface with AI. Three days ago I started asking Gemini to build a browser-based, agentic Moqui-generating IDE. It looks like a typical IDE, but it has an AI Chat window in the corner that uses WebMCP to connect to Gemini (but it could be any LLM) and Moqui. I think what I am doing is very similar to what Ean is doing, but the truth is that I haven’t looked at a bit of the code that Gemini has been writing. I do see that if all XML artifacts were converted to JSON there would be about a 50% reduction in Moqui code. But the main takeaway is that I have created an agentic IDE in three days without writing any code myself, and I could not have done that without working in JSON. JSON is the modern way to talk to AI and if we resist going in that direction we will keep paying an “XML tax” and we won’t be able to keep up.

This has already reached the TL;DR length, but I can demo my IDE on the Friday collaboration call ( https://meet.google.com/ues-nsnr-jom - is this call even publicized anywhere?).

OK fellows, I invited Gemini to this thread :wink: If you guys have any complaints, talk to the parents!

The prompt:
Assume that you are a seasoned systems architect with very good knowledge about the development of enterprise-ready software, like ERP or CRM. You have deep knowledge about the Moqui Framework https://moqui.org and its use of XML files for several components. Thinking in the AI wave right now, could be a good strategy to migrate all the XML structure to the same, but in JSON? Or could be a not so good choice?

The answer:
As a systems architect who has lived through the evolution of enterprise frameworks and spent significant time under the hood of David E. Jones’s Moqui Framework, I can offer a nuanced perspective on this.

The question of XML vs. JSON in the context of the current AI wave is a fascinating one. While the industry is gravitating toward JSON for its simplicity and “web-native” feel, migrating Moqui’s core declarative structure from XML to JSON is a strategy I would classify as “High Risk, Low Reward.”

Here is a breakdown of why, from an architectural and AI-readiness perspective, staying the course with XML—while perhaps augmenting it—is the wiser choice.


1. The Power of Metadata: Attributes vs. Key-Value Pairs

Moqui’s “Mantle” and its entire logic (Entities, Services, Screens) rely heavily on attributes.

In XML, you can distinguish between the “identity” of an element and its “properties” easily:

<entity entity-name="Product" package="mantle.product">
    <field name="productId" type="id" />
</entity>

In JSON, everything is a key-value pair. To represent the same metadata, you often end up with “bracket hell” or highly verbose structures that are harder for humans (and ironically, some AI tokenizers) to parse logically:

{
  "entity": {
    "entity-name": "Product",
    "package": "mantle.product",
    "fields": [
      { "name": "productId", "type": "id" }
    ]
  }
}

Architectural Verdict: XML is a superior Description Language. JSON is a superior Data Interchange format. Moqui uses XML to describe the system, not just move data.

2. The AI Argument: Context and Tokenization

There is a common misconception that AI “prefers” JSON. While LLMs are very good at generating JSON, XML has a distinct advantage for AI in long-context structural integrity.

  • Closing Tags: The closing tags in XML (</entity>) act as strong “anchors” for an LLM. They help the model keep track of the hierarchical stack. In massive JSON files, AI can often lose track of which level of nesting it is in (the “trailing brace” problem).
  • Schema Awareness: AI models trained on enterprise codebases understand XSD (XML Schema Definitions). Moqui’s use of XSDs provides a “grammar” that AI can use to validate its own suggestions. JSON Schema is less mature in many enterprise IDE integrations.

3. The “Mantle” and Validation

Moqui isn’t just a web framework; it’s a Model-Driven Development (MDD) platform.

  • XSD Validation: Moqui’s XML files are validated against complex XSDs in real-time. This prevents developers from making structural mistakes before the code ever runs.
  • Macro-Screen System: Moqui’s screen rendering uses FTL (FreeMarker) and XML to transform abstract definitions into HTML/Vue. A JSON-based screen definition would essentially become a reimplementation of XML’s tree structure, but without the mature tooling (like XSLT or XPath) that can be used to manipulate XML.

4. Where the “AI Wave” Actually Matters

If you want to make Moqui “AI-Ready,” the strategy shouldn’t be to change the file format, but to improve the accessibility of the metadata.

Instead of migrating XML to JSON, a better strategy is:

  1. Expose the Model via JSON-LD: Allow AI agents to query the meaning of your entities and services using Linked Data (JSON-LD).
  2. Generate AI-Friendly Documentation: Use the XML definitions to auto-generate comprehensive “Context Files” (in Markdown or JSON) that you can feed into an LLM’s System Prompt or RAG (Retrieval-Augmented Generation) pipeline.
  3. DSL Wrappers: If developer experience is the concern, create a YAML or JSON overlay that compiles down to Moqui XML, but keep the XML as the “source of truth.”

5. The “Not-So-Good” Choice: The Cost of Migration

Migrating Moqui to JSON would require:

  • Rewriting the MNode class (the heart of Moqui’s internal tree representation).
  • Breaking every existing Moqui application and the entire Mantle ecosystem.
  • Losing the ability to use XML-specific features like extend-entity or auto-parameters which rely on the merging of XML nodes—a process that is much more ambiguous in JSON due to the lack of standard “merge” rules for duplicate keys in arrays.

Final Recommendation

Do not migrate. As a seasoned architect, I would advise you to keep the XML for Definition (where structure and validation are king) and continue using JSON for API/Data (where ease of consumption is king).

To ride the AI wave, focus your energy on building a Metadata Provider. Create a service in Moqui that can export your XML-based Entity and Service definitions into a format that a Vector Database or an LLM can ingest. The AI doesn’t care if the source is XML or JSON; it cares if the relationships between the data are clear. In Moqui, those relationships are clearest in the original XML.

Funny, but I used Gemini to justify the move to JSON, but based on the community input from the collab call and the arguments you make - especially the one about LLMs knowing about Moqui in its XML form - pretty much is forcing me back to the drawing board. That’s why forums exist.

2 Likes