tc39 / proposal-json-parseimmutable

JSON.parseImmutable for creating Records and Tuples from JSON strings
https://tc39.es/proposal-json-parseimmutable/
MIT License
32 stars 1 forks source link

JSON.parseImmutable Proposal

Status

Stage 2

Champions:

Overview

This proposal complements the Records and Tuples Proposal. It was originally part of that proposal but split off into a separate proposal to reduce the scope of the core Records and Tuples proposal. #330

The problem being explored is ergonomic and efficient creation of a deeply immutable data structure from a JSON string.

JSON.parse(data, (key, value) => {
  if (typeof value === 'object' && value !== null) {
      if (Array.isArray(value)) {
        return Tuple.from(value);
      } else {
        return Record(value);
      }
  }
  return value;
});

Could be replaced with:

JSON.parseImmutable(data);