Comments (7)
Could be an enhancement.
Is there some JSON-schema spec about it?
from json-editor.
I don't believe there's any way to enforce ordering in JSON-schema, I think an object is by definition unordered in JSON. This would have to be something purely for display convenience. I'm thinking of modifying the sort comparator function in editors/object.js to fall back to alphabetical sorting if propertyOrder is not set on both properties being compared. If you want I can submit that as a pull request, enabled by a new schema options flag, something like alphabetize_properties.
from json-editor.
Are you creating the schema dynamically? If so, why can't you calculate propertyOrder
in advance?
Or do you also change the schema when the editor is active?
from json-editor.
I'm not creating a schema dynamically. I suppose I could load the json first, build a schema off of it and use that, but then I'd have to update the schema every time I added a new entry to the database, and I don't think you can switch out the schema on the fly.
My (simplified) schema looks like this:
{
type: "object",
options:
{
disable_collapse: true,
},
additionalProperties:
{
type: "object",
options:
{
collapsed: true,
disable_properties: true
},
additionalProperties: false,
properties:
{
name: { type:"string", title: "Name" },
cat: { type:"string", title: "Catagory" },
img: { type:"string", title: "Image filename"},
max: { type:"integer", title: "Max stack size" },
<.... many more properties>
},
format: "grid"
}
}
The (simplified) database looks like this:
{
"wood": {
"name": "Wood",
"cat": "goods",
"img": "wood.png",
"max": 100
},
"stone": {
"name": "Stone",
"cat": "goods",
"img": "stone.png",
"max": 100
},
"hay": {
"name": "Hay",
"cat": "goods",
"img": "hay.png",
"max": 100
},
"thatch": {
"name": "Thatch",
"cat": "goods",
"img": "thatch.png",
"max": 100
},
"peat": {
"name": "Peat",
"cat": "goods",
"img": "peat.png",
"max": 100
},
<100s more items...>
}
The items can be added and removed in the editor, and there are many of them, so it's nice to have them sorted to be able to find them when editing. There is no master list of all items, since admins are always adding more.
Anyway, I understand if this is a special use that's not broadly done. I've already made my own branch with the alphabetical sorting option, and I'm happy to just use that going forward if you'd rather not mess with it in the main branch.
from json-editor.
@rejemy Sounds like an interesting feature. Please submit a pull request.
from json-editor.
This is an interesting issue and I also support property sorting. What I would really like though is that the json Editor keeps the order the keys were in when they were loaded in. Currently, when json is provided to the json editor and the schema does not provide any property order, the editor decides on a new order by itself. In this case, I don't want to specify any order, just keep it as it was.
from json-editor.
Sorry I'd forgotten this issue was still open. My version of json-editor has diverged a bit by this point and I'm pretty happy with it, and it sounds like you'd rather keep the current ordering, so I'm going to close this.
from json-editor.
Related Issues (20)
- Can I Do Dependencies Only On the Default Value And Enum? HOT 1
- [bug]select2 setValue report a error and not select it HOT 8
- Starrating format isn't working properly HOT 1
- bug/regression: bool or number value does not show when remove_empty_properties=true and use_default_values=false
- Can Do a "WACTH" To Another Root "JSON Editor". HOT 4
- Auto generate schema for simple cases HOT 5
- Support for chained / nested watch HOT 2
- Add meta-data (schema builder) example HOT 1
- Validation of datetime-local fails when oneOf is used HOT 3
- An error occurs when a dependency is defined after the field that depends on it HOT 1
- Dependent field does not update when watched field changes HOT 1
- Failure to parse schema with "default": null due to unhandled exception in browser console
- select2 doesn't refer enumSource of item in array. HOT 12
- How do I add my syntax highlighting to Ace Editor? HOT 1
- test
- Enum wont be selected on load if it not the first element HOT 2
- Dependencies with false values not fullfilled HOT 1
- Adding a property breaks UI with a couple of exceptions in the console
- Cannot set (programmatically) value for "enum" string HOT 2
- compare fields HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-editor.