Uhhh

JSON.stringify, what the HECK did you just do?

> c.values[0]
{ char: '10001',
pinyin: '',
english: [],
code: '00031',
cjkdecomp: [ 'ra', '㇑' ] }

> JSON.stringify(c.values[0])
'{"char":"10001","pinyin":"","english":"[\\n\\n]","code":"00031","cjkdecomp":"[\\n\\"ra\\",\\n\\"㇑\\"\\n]"}'

Did you just turn array-valued entities inside an object into string-valued entities....?

Is that... is that in the spec, somehow?

> c.values[20000]
{ char: '壜',
pinyin: 'tan2',
english: [ 'variant of 罈|坛[tan2]' ],
code: '058DC',
cjkdecomp: [ 'a', '土', '曇' ],
ids: [ '⿰土曇' ],
analysis: '⿰土曇',
kind: 's' }

>
JSON.stringify(c.values[20000])

'{"char":"壜","pinyin":"tan2","english":"[\\n\\"variant of 罈|坛[tan2]\\"\\n]","code":"058DC","cjkdecomp":"[\\n\\"a\\",\\n\\"土\\",\\n\\"曇\\"\\n]","ids":"[\\n\\"⿰土曇\\"\\n]","analysis":"⿰土曇","kind":"s"}'

How... how the heck am I supposed to parse that up again correctly....?

Surely any sane person asking 'convert this JSON to a string' would expect it to convert it to a string that resembles the actual JSON...?

But this seems to be recursing over objects and turning all subproperties, themselves, into strings.....?

Who ordered that?

Why is this the default 'to JSON' routine built into Node?

What's the rational explanation that I'm missing here?

Node 8.11.1, by the way. The current LTS. It's not an ancient one.

And yep, that output certainly does NOT JSON.parse() back as what went in.

> JSON.parse(x)
{ char: '壜',
pinyin: 'tan2',
english: '[\n"variant of 罈|坛[tan2]"\n]',
code: '058DC',
cjkdecomp: '[\n"a",\n"土",\n"曇"\n]',
ids: '[\n"⿰土曇"\n]',
analysis: '⿰土曇',
kind: 's' }
>

@natecull How are you feeding this back in? It seems to be trying to escape newlines as well.

@Tablesaw @[email protected] ah, I think I know what happened.

My evil fed back on me.

I added custom methods to Array.prototype, and I guess that made JSON.stringify think my arrays had to be stringed.

sigh

Oh well.

@natecull @[email protected] I suppose you could try using eval() instead of JSON.parse().

@Tablesaw @[email protected]

and yep, removing my prototype extensions and putting them back as functions, stringify is good again

Sigh.

Well, it was clearly marked as evil, so I have nobody to blame but myself.