tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create empty array

nirenrc opened this issue · comments

Hello

I would like to create empty array, could not find working syntax using "Set" API. e,g. to achieve below json
{
"home": {
"kitchen": {
"refrigerator": []
}
}
}

what would be path syntax in Set API or any other to achieve same?

Niren

Hi, try the SetRaw function.

sjson.SetRaw(json, "home.kitchen.refridgerator", "[]")

Thank You

Yes, it works. Other option of "-1" works too
sjson.SetRaw(json, "home.kitchen.refridgerator.-1", "")

Niren