Click here to Skip to main content
15,891,777 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralJust Lazy... Pin
#realJSOP3-Apr-19 4:12
mve#realJSOP3-Apr-19 4:12 
QuestionRe: Just Lazy... Pin
megaadam3-Apr-19 4:21
professionalmegaadam3-Apr-19 4:21 
AnswerRe: Just Lazy... Pin
#realJSOP3-Apr-19 4:31
mve#realJSOP3-Apr-19 4:31 
AnswerRe: Just Lazy... Pin
OriginalGriff3-Apr-19 4:38
mveOriginalGriff3-Apr-19 4:38 
GeneralRe: Just Lazy... Pin
#realJSOP3-Apr-19 4:57
mve#realJSOP3-Apr-19 4:57 
GeneralRe: Just Lazy... Pin
Marc Clifton3-Apr-19 4:32
mvaMarc Clifton3-Apr-19 4:32 
GeneralRe: Just Lazy... Pin
dandy723-Apr-19 10:30
dandy723-Apr-19 10:30 
QuestionJSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 2:34
mvaMarc Clifton3-Apr-19 2:34 
Do you prefer to always wrap the JSON in an outer object?

For example, a call to a credit card processor to get supported credit cards. Do you prefer simply the array returned:

[
    "AM",
    "DI",
    "EB",
    "EP",
    "MC",
    "VI"
]


or the array wrapped in an outer "object":

{
  "PaymentMethods": [
    "AM",
    "DI",
    "EB",
    "EP",
    "MC",
    "VI"
  ]
}


If one or the other, why?

Personally, I'm leaning toward the second form, which forces the Javascript writer to at least initially use the PaymentMethods tag:

let ccs = resp.PaymentMethods;

Which I think improves code readability. It's also more maintainable IMO, as perhaps other tags at some point might be added -- one simple thing that comes to mind is a flag that indicates whether ACH is supported (mind you, these are all concrete examples of the general question of JSON tags):

{
  "PaymentMethods": [
    "AM",
    "DI",
    "EB",
    "EP",
    "MC",
    "VI"
  ],
  "SupportsACH": true
}


Using an outer object wrapper doesn't break the code if additional JSON elements are added later.

So...thoughts?

Marc
Latest Article - Azure Function - Compute Pi Stress Test

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

AnswerRe: JSON responses -- what's your preference? Pin
W Balboos, GHB3-Apr-19 2:36
W Balboos, GHB3-Apr-19 2:36 
AnswerRe: JSON responses -- what's your preference? Pin
  Forogar  3-Apr-19 2:47
professional  Forogar  3-Apr-19 2:47 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 2:52
mvaMarc Clifton3-Apr-19 2:52 
AnswerRe: JSON responses -- what's your preference? Pin
Nish Nishant3-Apr-19 2:53
sitebuilderNish Nishant3-Apr-19 2:53 
AnswerRe: JSON responses -- what's your preference? Pin
megaadam3-Apr-19 3:16
professionalmegaadam3-Apr-19 3:16 
AnswerRe: JSON responses -- what's your preference? Pin
Mike Hankey3-Apr-19 3:24
mveMike Hankey3-Apr-19 3:24 
AnswerRe: JSON responses -- what's your preference? Pin
GuyThiebaut3-Apr-19 3:29
professionalGuyThiebaut3-Apr-19 3:29 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 4:13
mvaMarc Clifton3-Apr-19 4:13 
GeneralRe: JSON responses -- what's your preference? Pin
Scott Serl3-Apr-19 6:24
Scott Serl3-Apr-19 6:24 
GeneralRe: JSON responses -- what's your preference? Pin
bence983-Apr-19 22:33
bence983-Apr-19 22:33 
AnswerRe: JSON responses -- what's your preference? Pin
User 48350473-Apr-19 3:48
User 48350473-Apr-19 3:48 
AnswerRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 4:00
mve#realJSOP3-Apr-19 4:00 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 4:15
mvaMarc Clifton3-Apr-19 4:15 
GeneralRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 4:20
mve#realJSOP3-Apr-19 4:20 
GeneralRe: JSON responses -- what's your preference? Pin
dandy723-Apr-19 10:21
dandy723-Apr-19 10:21 
AnswerRe: JSON responses -- what's your preference? Pin
User 48350473-Apr-19 4:10
User 48350473-Apr-19 4:10 
AnswerRe: JSON responses -- what's your preference? Pin
dan!sh 3-Apr-19 4:27
professional dan!sh 3-Apr-19 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.