Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86379 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21415 invoked from network); 25 May 2015 15:40:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 May 2015 15:40:55 -0000 Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.176 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-ie0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:33034] helo=mail-ie0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/80-17853-48243655 for ; Mon, 25 May 2015 11:40:53 -0400 Received: by iebgx4 with SMTP id gx4so74636162ieb.0 for ; Mon, 25 May 2015 08:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=oeGPTH3cIspsTM5svzMRjJ7R45hlr8QiybyfSro6IF4=; b=US/A2tYdg14S4qLwY/yaPHmaRKdMCjw5RWhG+etPhHB2249ryWj9/RHDBb4SywvAjX Naycx4hPmDWXTUcRejA6Ofco6iheaJ+BL2+z+jdHfJIU/9Ug4MNiatBe7o61DbXZWO7x Q7HBgdQO0f7hWoL2tXaudbC9s+AjrGVuTG+zMYiNqH9mGEeTMMFuPza5O/UIgY0Up3QJ lWuUiUuNhRdhBL1IjEAnB+LWizNq2bZuCsRFZTzuOCwKYaPHZbYnuJiZ36vn6zCikxJY 7lObcsk7ehgtcK0AxjIrl4si+OhnbfpbT8YOMif4ueWW1AIND6YXzLNKp6R1uI6G+nDC 4AkA== MIME-Version: 1.0 X-Received: by 10.107.46.39 with SMTP id i39mr29239178ioo.8.1432568449606; Mon, 25 May 2015 08:40:49 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.153.74 with HTTP; Mon, 25 May 2015 08:40:49 -0700 (PDT) In-Reply-To: <5E3BAD6C-BC6B-4BBC-92E5-37AD7A6891E0@gmail.com> References: <5E3BAD6C-BC6B-4BBC-92E5-37AD7A6891E0@gmail.com> Date: Mon, 25 May 2015 16:40:49 +0100 X-Google-Sender-Auth: PAdQHsfxb6jec56jyhUaqXkPPKA Message-ID: To: Alexey Zakhlestin Cc: PHP internals list Content-Type: multipart/alternative; boundary=001a1137805e8e2b230516e9d5ad Subject: Re: [PHP-DEV] [RFC] JSON number to string From: bukka@php.net (Jakub Zelenka) --001a1137805e8e2b230516e9d5ad Content-Type: text/plain; charset=UTF-8 Hi, On Mon, May 25, 2015 at 7:59 AM, Alexey Zakhlestin wrote: > > > I'm not sure how JSON Schema would help here. The issue is about > converting from json's huge numbers to limited PHP's numbers. Schema just > doesn't have notion of native types > > The idea would be to use JSON schema to specify structure of the JSON and select just the specific parts that can be converted to string. Let's imagine that you have object with this structure: { "a": 1.23234, "b": 11111222222222222.111111111 } Now you really don't want to loose precision for b but you would like to use float for a. You can create a simple json schema: { "title": "Simple Object Schema", "type": "object", "properties": { "a": { "type": "number" }, "b": { "type": "string" } } } The great thing on JSON Schema is that it is not limited on the specified fields (the schema of json core schema does not disable additionalProperties which means that any additional properties are allowed). That means that we could add our parameter to specify a class of the object. For example if we create classes that you proposed in the previous thread, we could do following: { "title": "Simple Object Schema", "type": "object", "properties": { "a": { "type": "number" }, "b": { "type": "object", "class": "Json\Float" } } } It would probably require some allowing only classes that implements some interface which allows JSON serialization (encoding) as well as unserialization (decoding). That could be also used for user classes. We would also need some flags to select type of the validation (strict validation, validation with conversion if possible...). There is much more that could be done including overloading validation errors... JsonSchema adds of course more features that are however off-topic... Anyway, as I told in a previous thread, while approach of this rfc solves > immediate problem, it is not future-proof flexible and exposing low-level > type based parsing is a better idea IIRC your initial proposal was about converting everything to objects which is not flexible at all as it suffers exactly from the same problems as this RFC. The only difference is using object instead of string. I think that the above is much more flexible... However as I said before it is quite a big feature that could be done only in the minor version and requires considerably more time for implementation. Cheers Jakub --001a1137805e8e2b230516e9d5ad--