Click here to Skip to main content
14,361,747 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 5:12
mve#realJSOP3-Apr-19 5:12 
QuestionRe: Just Lazy... Pin
"mega"-in-a-fake-beard3-Apr-19 5:21
professional"mega"-in-a-fake-beard3-Apr-19 5:21 
AnswerRe: Just Lazy... Pin
#realJSOP3-Apr-19 5:31
mve#realJSOP3-Apr-19 5:31 
AnswerRe: Just Lazy... Pin
OriginalGriff3-Apr-19 5:38
protectorOriginalGriff3-Apr-19 5:38 
GeneralRe: Just Lazy... Pin
#realJSOP3-Apr-19 5:57
mve#realJSOP3-Apr-19 5:57 
GeneralRe: Just Lazy... Pin
Marc Clifton3-Apr-19 5:32
protectorMarc Clifton3-Apr-19 5:32 
GeneralRe: Just Lazy... Pin
dandy723-Apr-19 11:30
memberdandy723-Apr-19 11:30 
QuestionJSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 3:34
protectorMarc Clifton3-Apr-19 3: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 Balboos3-Apr-19 3:36
mveW Balboos3-Apr-19 3:36 
AnswerRe: JSON responses -- what's your preference? Pin
  Forogar  3-Apr-19 3:47
professional  Forogar  3-Apr-19 3:47 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 3:52
protectorMarc Clifton3-Apr-19 3:52 
AnswerRe: JSON responses -- what's your preference? Pin
Nish Nishant3-Apr-19 3:53
sitebuilderNish Nishant3-Apr-19 3:53 
AnswerRe: JSON responses -- what's your preference? Pin
"mega"-in-a-fake-beard3-Apr-19 4:16
professional"mega"-in-a-fake-beard3-Apr-19 4:16 
AnswerRe: JSON responses -- what's your preference? Pin
Mike Hankey3-Apr-19 4:24
professionalMike Hankey3-Apr-19 4:24 
AnswerRe: JSON responses -- what's your preference? Pin
GuyThiebaut3-Apr-19 4:29
professionalGuyThiebaut3-Apr-19 4:29 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 5:13
protectorMarc Clifton3-Apr-19 5:13 
GeneralRe: JSON responses -- what's your preference? Pin
Scott Serl3-Apr-19 7:24
memberScott Serl3-Apr-19 7:24 
GeneralRe: JSON responses -- what's your preference? Pin
bence983-Apr-19 23:33
memberbence983-Apr-19 23:33 
AnswerRe: JSON responses -- what's your preference? Pin
q1213q3-Apr-19 4:48
memberq1213q3-Apr-19 4:48 
AnswerRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 5:00
mve#realJSOP3-Apr-19 5:00 
GeneralRe: JSON responses -- what's your preference? Pin
Marc Clifton3-Apr-19 5:15
protectorMarc Clifton3-Apr-19 5:15 
GeneralRe: JSON responses -- what's your preference? Pin
#realJSOP3-Apr-19 5:20
mve#realJSOP3-Apr-19 5:20 
GeneralRe: JSON responses -- what's your preference? Pin
dandy723-Apr-19 11:21
memberdandy723-Apr-19 11:21 
AnswerRe: JSON responses -- what's your preference? Pin
q1213q3-Apr-19 5:10
memberq1213q3-Apr-19 5:10 
AnswerRe: JSON responses -- what's your preference? Pin
lw@zi 3-Apr-19 5:27
professional lw@zi 3-Apr-19 5: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.