Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent an array with empty elements in JSON?

I have an array in JavaScript that looks like this:

var pattern = [ ["C5", 3], , , , , , , , ["C5", 3], , , ] 

I want to store it in a json file like this:

{
  "pattern": [
               ["C5", 3], , , , , , , , ["C5", 3], , ,
             ]
}

JSONLint tells me this:

Parse error on line 6:
...        ],        ,        ,        
---------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

So I understand I can't let the space between commas empty. What's similar to empty, but is accepted by JSON standards?

This pattern file is part of a Javascript Music Tracker I'm making that's similar to impulse tracker, and I want the json file to be as clean as possible.

like image 470
eri0o Avatar asked Jul 28 '26 05:07

eri0o


1 Answers

If you want to have empty space in JSON, you should fill it with null.

Example:

var pattern = [ ["C5", 3], null, null, null, null, null, null, null, ["C5", 3], null, null, null, null, ...... ]
like image 179
Richard Kho Avatar answered Jul 29 '26 19:07

Richard Kho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!