That way Fetch and XMLHttpRequest can use it more directly (and other web platform entry points that need JSON parsing). Alternative is an abstract operation, which might be a little clearer usage wise.
Any preference?
I missed that %JSON% already exists. Could I write something like
Return ? Invoke(%JSON%, "parse", 芦 _jsonSource_ 禄).
then?
I'd prefer we just name the intrinsic so you can call it directly.
With the Invoke, you'd be calling whatever I happened to install on the JSON object under "parse"; it definitely would need a direct name.
Thanks, I'll work on a PR. How would I end up using it in prose afterwards? Just
Return ? %JSONParse%( _jsonSource_ )
or something more involved?
That seems right to me!
Return ? %JSONParse%( jsonSource )
No, that's not correct. That's only correct if it's an abstract operation ("JSONParse", no %s), which indeed is neater.
If we expose it as a named intrinsic, we'd need
Return ? Call(%JSONParse%, undefined, 芦 jsonSource 禄).
I think an abstract operation would be nicer if we can get away with it.
If we do that we can also make it encompass only steps 2-6 of the JSON.parse function.
Okay, I think we can just add an abstraction in Infra to make the difficulty go away for everyone else in the web platform. (And maybe also require UTF-8 there at the same time when the input is bytes.)
Most helpful comment
No, that's not correct. That's only correct if it's an abstract operation ("JSONParse", no %s), which indeed is neater.
If we expose it as a named intrinsic, we'd need
I think an abstract operation would be nicer if we can get away with it.
If we do that we can also make it encompass only steps 2-6 of the JSON.parse function.