in Education by
I have seen valid JSON written this way: { "version": 1 , "object": { "one": 1 , "two": 2 , "three": 3 , "four": 4, , "five": 5 } , "array": [ 1 , 2 , 3 ] , "people": [ { "firstname": "Jacob", , "lastname": "Ford" } , { "firstname": "Marcin" , "lastname": "Wichary" } ] } My guess as to the the primary advantage is that the addition or removal of one line of data will (with a few exceptions) be diff'd as just that: a single-line addition or deletion. As opposed the more typical JSON presentation, with trailing commas, where appending an item to the end of an array or object requires editing the line before it, to add a comma. Is there a name for this JSON presentation convention, with leading commas, and commas placed in same column as opening/closing brackets? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
It appears to generally be referred to as comma-first notation (though is sometimes also called leading comma notation), and can apply to more than just JSON. SQL commands are another good example. npm's code style guide requires it for all comma-separated lists. Airbnb's forbids it. My assumption about this style producing cleaner diffs was correct; however some prefer to achieve the same goal by sticking with trailing commas, but always including an (unnecessary) dangling comma after the final item. The aforementioned Airbnb code style guide, in the section immediately after forbidding comma-first notation, requires dangling commas after lists, explicitly for cleaner diffs. There is one additional advantage proponents point to, which is that typographical errors become much more apparent in comma-first notation. This gist by the inventor of npm is often cited, which I'll excerpt here: // error in standard style var a = "ape", b = "bat", c = "cat", d = "dog" e = "elf", f = "fly", g = "gnu", h = "hat", i = "ibu"; // error in comma-first style var a = "ape" , b = "bat" , c = "cat" , d = "dog" e = "elf" , f = "fly" , g = "gnu" , h = "hat" , i = "ibu" ;

Related questions

0 votes
    Which of these class allows us to define our own formatting pattern for dates and time? (a) DefinedDateFormat ... Expressions of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    There are similarities between the instructor entity set and the secretary entity set in the sense that ... Database Systems Design and Implementation of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    character constant that begins with a backslash and enclosed within inverted commas Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    character constant that begins with a backslash and enclosed within inverted commas Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    Regex has a character for or but what is the character for and? For example, say I have a folder with the following files: ... to get an and on a regex and got confused. data x...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I have a json file contains a icons object like this: "icons" : { "logo" : "fa fa-caret-down ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    This my my JSON: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0 ... the values, How can I do it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    Which of the following function is used as a consequence of not including semicolons, commas or whitespace ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Positional parameters are coded first before any Keyword parameter and parameters are separated by ‘Commas’ only. State whether true or false? A - False B - True...
asked Dec 4, 2020 in Technology by JackTerrance
0 votes
    Name the actor classes used in Observer pattern....
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Name the actor classes used in Memento pattern....
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    The relation EMPDT1 is defined with attributes empcode(unique), name, street, city, state, and pincode. ... topic in division Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    How to print details in the pattern given in java constructors like this Write a program that would print the ... - WallsStreat ?? Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
...