Git Product home page Git Product logo

Comments (7)

schmunk42 avatar schmunk42 commented on May 22, 2024

Could be an enhancement.

Is there some JSON-schema spec about it?

from json-editor.

rejemy avatar rejemy commented on May 22, 2024

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.

schmunk42 avatar schmunk42 commented on May 22, 2024

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.

rejemy avatar rejemy commented on May 22, 2024

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.

pmk65 avatar pmk65 commented on May 22, 2024

@rejemy Sounds like an interesting feature. Please submit a pull request.

from json-editor.

snipercup avatar snipercup commented on May 22, 2024

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.

rejemy avatar rejemy commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.