JSON null (help)

Sorry my stroke sucks which I cannot read great
Anyway if anyone can tell me this null

on my JSON on my item looks like this
[
{
“nmbr”:1,
},
{
“nmbr”:2,
}
]

when I remove one (like “nmbr”:2) it shows this

[
{
“nmbr”:1,
}
]

then when I add another item it looks like this now

[
{
“nmbr”:1,
},
null,
{
“nmbr”:3,
}
]

Any idea how to add one after I deleted one, is there a way to clean all null?
Is there a simple part to just to clean and leave the JSON

Thank you,
sorry If I sound hard to understand

(text-to-speech)

Google for JSON validator online, it will show you your JSON mistakes like commas where they are not supposed to be, etc.

How are you editing your json file?

[{“nmbr”:1,“nmbr”:2}]

Use this link to validate your json

Thanks, So this is what happens,
test 1 - (three belts on my game)
jsonnull


So I add 3 belts and it shows no null yet

test 2 - (two belts after I remove one (so {“nmbr”:2…} I use

table.remove( mySettingBelt,2 )
saveTable(mySettingBelt, “Belt.json”)
which is nice )


test 3 - but now (three belts after I add one more back, and then a null, but the next new one it {“nmbr”:4…} which looks like this


So after save it add null
saveTable(mySettingBelt, “Belt.json”)

So yeah it works with the belts but it will be just a huge mess of tons or null after I have thousands of belts

Tim G. (null nerd) :slight_smile:

Do you want to keep null in your lua table but not save them in your JSON files? It seems like you put them there on purpose because I checked and table.remove leaves no gaps, if possible.

So when I remove one image, it removes the image and I removes the table, and save the JSON. So I want all null gone, but when I add the next new one, I add the image, and add the save JSON. So the only null seems to add a null after I save the JSON
obviously I am missing about some number which is making it wrong :frowning:

basically I just want null to leave of the world :slight_smile: (well only on the game :-))

OK, thank you all, I got it (well kinda)
so when I remove a belt, It adds a junk(ish) I just added a number, I then find any junk and use the number and when I add a new belt, it will use any number in the junk, if no junk just add the next top number. I hope any of that makes sense my stroke(Aphasia) is very weird. :slight_smile:
Now I need to add some split belt :slight_smile:

If you use table.remove to remove elements and table.insert (without specyfing an index) to add new ones you won’t create gaps. The nulls will appear if you always do this like: mySettingBelt[beltNmbr] = myBelt.
My advice is to use table.insert(mySettingBelt, myBelt) or mySettingBelt[#mySettingBelt] = myBelt. This way you won’t create a gap, and won’t need to keep track where you have gaps in your table.

I found you an article on the topic, I hope it helps :slight_smile: https://riptutorial.com/lua/example/8360/avoiding-gaps-in-tables-used-as-arrays

it is not easy to provide you with support if we can’t see the code, eventually there may be no need to use arrays or tables at all…

arrays can be very complicated sometimes, or let me say you will mess it up if you don’t know how to handle them specially when adding, or deleting items from them

so be careful

Thank you so much all of you, you all rule, helps me so much