What I’m trying to do:
I’m new to Anvil, I was wondering how I can create JSON schema input form for the user.
I mean I can drag and drope text and dropdown for each item in json, but in looking for something that will convert json schema to user input form automatically.
{
“title”: “NewApp”,
“description”: “NewAppForTestJson”,
“type”: “object”,
“required”: [“main_test”],
“properties”: {
“main_test”: {
“type”: “string”,
“title”: “Test”,
“enum”: [“test1”,“test2”]
}
}
}
Welcome to the Forum!
I haven’t seen anyone build such a thing for others to use.
But you can build one! You would use Python code to:
- Pick apart the Schema definition, one JSON object (value definition) at a time
- Render each such object and property appropriately:
a. An enum as a DropDown,
b. A number as a TextBox,
c. A nested object as a container component (ColumnPanel, LinearPanel, …)
etc.
Since JSON Schemas (like JSON) are defined recursively, your parser-builder will probably invoke itself (recursively), too, for the nested values.
While this is certainly feasible, handling nested entries (such as lists and objects) will take some forethought, and much familiarity with Anvil’s Components. Take your time to study the available docs and tutorials, and run your own experiments. That will pay off handsomely.
The bad thing about Anvil is that there isn’t a way to do that out of the box.
The good thing about Anvil is that it’s very easy to make your own version, so you can customize it exactly the way you want it.
Here you can see an example of something similar: Input_box() and alert2()
One shortcut for @seregaej would be to just read up on extending the built in json encoder with your own json.JSONDecoder
, then you could encode-decode directly to and from anvil components, using .dumps()
and .loads()
Here is just one example (there are many to be found):
Thanks a lot for all your responses.
@p.colbert, “Render each such object and property appropriately”, yes I think about it, just want to make sure there is no built-in functionality.
@ianb, thanks i will check it.
Perhpas there is something helpful in the survey and reporting platform here.
Questionarries and reports are represented as dictionaries/JSON.
There is an embedded JSON editor for making charts.
Anvil can seemingly do anything.