Re: [whatwg/url] toJSON() serialization (#137)

I agree with @stevenvachon. As an end user, I would expect a URL to serialize to the full `href` string the same way Date serializes to a full ISO string.

During deserialization, the user can pass the string into the `URL()` constructor the same way you pass the ISO string into the `Date()` constructor.

Here's an example:

```js
var data = {
  theUrl: new URL("https://example.com/foo"),
  theDate: new Date("2017-02-02T17:06:41.229Z")
};

var str = JSON.stringify(data);
// "{"theUrl":"https://example.com/foo","theDate":"2017-02-02T17:06:41.229Z"}"

var clone = JSON.parse(str);

new Date(clone.theDate).valueOf() === data.theDate.valueOf(); // Current this is true
new Url(clone.theUrl).href === data.theUrl.href; // I would expect this to be true
```

Note that the Date does *not* stringify as `{fullYear: 2017, month: 1, date: 2}`. Neither should the URL.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/137#issuecomment-277020662

Received on Thursday, 2 February 2017 17:16:44 UTC