Advice on the data model that I'm using

I’m working on an application that has been going OK, but I’ve now hit a wall. It feels to me like one of the problems comes down to the fact that the JSON nodes have no identifiers. This makes it hard to keep track across the whole JSON structure when I want to make changes to nodes, particularly if it gets big (and it does).

Is there a way to associate an identifier with a JSON node so that I can change the node name without losing track of its child nodes?

The more I look into this the more I’m wondering whether I have picked the wrong data storage model for this application. Though I’m no fan of relational databases, is this maybe a case for tables, rows and columns? Or would a MongoDB document allow me to do the sort of querying, tracking and editing that I want to do (I’m think this because Mongo uses JSON IIRC)?

Any advice would be appreciated. I’ve been working on this idea for quite a while and it’s a little frustrating to have uncovered such a serious problem at this stage.

An example of the JSON I’m creating is below. It shows a couple of options between which I want to make a choice, together with some relevant parameters and the objective and personal scores for each parameter. The scorecard value is arrived at by some maths using the scores.

Thanks,

Ian.

{
	"Easter eggs" : {
		"M&S" : {
			"Cocoa content" : {
				"IndependentScore" : "59",
				"MyScore" : "90"
			},
			"Cost" : {
				"IndependentScore" : "48",
				"MyScore" : "40"
			},
			"Scorecard Value" : "59.25"
		},
		"Hotel Chocolat" : {
			"Cocoa content" : {
				"IndependentScore" : "80",
				"MyScore" : "93"
			},
			"Cost" : {
				"IndependentScore" : "15",
				"MyScore" : "40"
			},
			"Scorecard Value" : "57"
		}
	}
}

If your json gets big and complicated then it’s time to switch to a relational database. Your problems will collapse as soon as the data is in a database.

1 Like

Thanks for the reply. I didn’t want to resort to SQL because the last time I looked at it the support in Xojo was not that good. Maybe it’s changed; I’ll take a look. I think I will also need to go and dust off my copy of Codd’s rules…

Please explain in more detail what you mean. My preferences data has 18 tables these days in SQLite:

think OOP, from JSON to Class/Object from Object to JSON.
No need for IDs

Well yes Object to JSON, but it should be able to recursively serialize without the need for unique node IDs. There are example projects around somewhere. I think one by Kem.

i would start with a list of objects then think about for save and how to load.
with objects you could make a interface with 2 methods to give json and get json.
this interface you can use at all you classes.