I am trying to find information on best practices for json data. I am working on a client server app that will contain family information. For purposed of this question, this is an oversimplification of the database. I have a family table, an address table, and a family members table. There are also a number of other tables that contain email addresses, phone numbers, etc. For each family, there can be multiple addresses (for the old folks that fly south for the winter), and multiple family members and each family member can have multiple phone numbers and email addresses. The family UID is in each table to enable linking. To retrieve all information for a family, should I build a complex JSON string that contains all of the data that needs to be parsed out manually or should it be individual calls, 1 for the family details, 1 for the addresses, 1 for the family members, 1 for each family members email addresses, and 1 for each family member's phone numbers? The single call seems very complicated but the alternative seems like a lot of overhead with connections, etc.

Recommended Answers

All 3 Replies

There's no magic to be done. You should load at first what you'll display right on to your users, details can be loaded latter.
Example: If your home screen is just the family members names, there's no need to load all the data at once.
If you need to click on a button to see the phone numbers, the phones can be loaded alone.
It's all about finding the best cost/benefit for your app.

Let me ask that differently. If I need all of the data at the same time (printing a report for example), for each family, should I create the complicated single JSON string or create multiple JSON strings?

It's easier if you get all the data in a single json but the band consumption is lower if you don't load the same data twice.
If some data(one address for example) is the same for various records(family members in this case) you can get it as a stand alone json and them link them with the family menbers on yout UI.
This way the bandwith consumption will be lower but the processor consumption will be higher.
I'd take apart the data if yours users have decent machine and browsers.
I say so because I once tried to do a rich UI with JS on a project that was used by old pcs on IE 7. Guess what? It crashed a lot. In that case more bandwith consumption and less processor was the key to success.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.