Just a bug report, here. I'll let the jjs session speak for itself. $ jjs -version nashorn 1.8.0_77 jjs> var a = JSON.parse("[]") jjs> a.length 0 jjs> JSON.stringify(a) [] jjs> a.push("foo") 1 jjs> a.length 2 jjs> JSON.stringify(a) [0,"foo"]
For the moment, I have a workaround that replaces JSON.parse() with a function that recursively replaces empty arrays with array literals. Since they don't exhibit the same bad behavior: jjs> var b = [] jjs> b.length 0 jjs> JSON.stringify(b) [] jjs> b.push("foo") 1 jjs> b.length 1 jjs> JSON.stringify(b) ["foo"]