My web users can choose among zero, one or more services (i.e. selectable with checkboxes). The choices should default to only service1.

The list of possible services is available via REST API. It could expand/change over time.

In a DB, I need to store the users choices (json format). But ideally, a "null record" there would mean the default. Order doesn't matter. Some service options would be stored too.

The problem with a simple object (dictionary)

a = {
   service2: { someOptions }

is that the default {} or null/undefined means no service selected.

Is there a clever way to handle this?


I would simply store the user's selections. That is, null=nothing selected. It is a bit unclear to me why you say:

ideally, a "null record" there would mean the default

The required extra storage space seems comparatively small. Also, consider what you want to happen if, in the future, you decide that service1 is no longer the default, but instead your new fancy service5? Do you want switch to happen for old users too?

  • ah, good point on changing default. – bebbi May 11 '17 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.