wso2 / jaggery

The delicious Javascript framework
Apache License 2.0
115 stars 175 forks source link

Improve serializeJSON() #187

Open fschaefer opened 6 years ago

fschaefer commented 6 years ago

This commit tries to improve serializeJSON() to get closer to rfc4627. It includes a more proper quoting of strings and output of integers instead of floats where appropriate.

Purpose

At the moment the serializeString() method replaces only a subset of control characters that are allowed in JSON, hence stringify() may not serialize to valid JSON.

Goals

Add a better string quoting, closer to rfc4627.

Approach

Add a quote() method that walks through the chars of a string and replaces all escapable chars to their quoted "\uXXXX" counterpart.

CLAassistant commented 5 years ago

CLA assistant check
All committers have signed the CLA.