π§Ύ Case β Loading Data from JSON in AppML: Power Your App with Modern Data
π§² Introduction β Why JSON is the Ideal Format for AppML
JSON (JavaScript Object Notation) is the most widely used data format in modern web development. It’s lightweight, easy to parse, and pairs perfectly with AppML. Whether you’re pulling records from an API or using a static data file, JSON is the go-to structure for creating dynamic, data-driven web apps using AppML.
π― In this guide, youβll learn:
- How to load JSON files into AppML using
appml-data
- How JSON fields bind to HTML using
{{ }}
- How to structure your JSON for AppML compatibility
- Practical use cases and advanced integration options
π What Should JSON Look Like for AppML?
AppML expects your JSON to be an array of objectsβeach representing a single record, with consistent field names.
β
Example: data/products.json
[
{ "id": 1, "name": "Laptop", "price": 1000 },
{ "id": 2, "name": "Phone", "price": 500 },
{ "id": 3, "name": "Tablet", "price": 700 }
]
Each object in the array maps directly to one record in your app.
π§Ύ HTML Example β Displaying JSON Data
<div appml-data="data/products.json">
<p>{{name}} β ${{price}}</p>
</div>
β AppML:
- Loads
products.json
using AJAX - Iterates through each record
- Replaces
{{name}}
and{{price}}
with values from each object
π§ Combine JSON with Models
For structured data, validation, and forms, pair your JSON file with a model:
<div
appml-data="data/products.json"
appml-model="models/product-model.json">
<p>{{name}} β ${{price}}</p>
</div>
β
Sample Model (product-model.json
)
{
"rows": 10,
"orderby": "name",
"fields": [
{ "name": "name", "required": true },
{ "name": "price", "datatype": "number" }
]
}
βοΈ Adds paging, sorting, and required field validation.
π Filtering JSON Data
AppML lets you filter data before it appears on screen:
β JavaScript Controller Snippet
myAppML.onshow = function() {
myAppML.filter = "price > 600";
};
Only records where price > 600
will be displayed.
πΎ Editing JSON Data (Form Example)
AppML can display JSON records in a form-like layout:
<div
appml-data="data/products.json"
appml-model="models/product-model.json">
<input name="name">
<input name="price" type="number">
<button appml-submit>Save</button>
</div>
Note: You canβt write back to a local JSON file from the browser. Use a server API for POST/PUT.
π§° Use Cases for JSON in AppML
π¦ Scenario | π¬ Why JSON Is Perfect |
---|---|
Product catalogs | Fast and structured |
Static profile lists | Loads easily on any device |
Academic data reports | Exported JSON fits AppML instantly |
API responses | Ideal for dynamic updates |
Form-driven UIs | Structure and validate input |
π Summary β Recap & Key Takeaways
JSON is AppML’s most powerful and flexible data format. It enables you to quickly display, filter, and interact with structured data, whether it’s local or coming from an external API.
π Key Takeaways:
- Use
appml-data="file.json"
to load JSON - JSON must be an array of records (objects with consistent keys)
- Combine with models to enable forms, sorting, and validation
- Use controllers for filtering, custom logic, and pagination
- Canβt write back to local JSONβrequires backend handling
βοΈ JSON + AppML = low-code, high-efficiency data-driven applications.
β FAQs β Working with JSON in AppML
β Can AppML load JSON from external APIs?
β
Yes, as long as the API returns a JSON array and has CORS enabled.
β Do I need a model to use JSON?
β No, but using a model adds structure, sorting, and form validation features.
β What happens if one record in the JSON is missing a field?
β
AppML still renders it. The missing fieldβs {{}}
will simply be blank.
β Can I edit and save back to the JSON file?
β Not directly. Use a server-side script (PHP, Node.js, etc.) to handle data updates.
β Can JSON be nested (objects within objects)?
β οΈ Not recommended. AppML works best with flat JSON records.
Share Now :