Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118323 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26736 invoked from network); 30 Jul 2022 12:49:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Jul 2022 12:49:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4D14B180381 for ; Sat, 30 Jul 2022 07:48:41 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 30 Jul 2022 07:48:37 -0700 (PDT) Received: by mail-ej1-f44.google.com with SMTP id rq15so7045630ejc.10 for ; Sat, 30 Jul 2022 07:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=7JQhtUw2I/q1ogmrnPxupgZXyV5smmPgsvtEpCJLT20=; b=dTPIAKqcmQKmp2FpREYGfdFllC/E4ytsAGePoILGgQQroH6HZ95LTLXqzLhlcDGm5v 62C7ATePa2ZIYGTMyUvupv31IXzTmGrZvm8CEXAolnJznCADDtjnd1iWvpft5a/VxKLj RauhtCT55LDxTbKq8O3Rc1RdjHs+ef29+UuX86oCeYxQyQtXMyFfzJh1jQCs+mMAoSZ3 kYzfMWJX+hIZwqVWddiy0ujUnHpphak4WgsIzR6AsEedWljqlz2d5rLYKABAQSl9mBBQ QmjKIf3VWUdt0W/GSUPTaQIejBd0LpKuCwa6FgIpL+NiNdk5ReugcLw0Gn/prETQOli+ a+WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=7JQhtUw2I/q1ogmrnPxupgZXyV5smmPgsvtEpCJLT20=; b=eVOaq4Yf3ywF23dcTO0p28gC+Eg5xUK0TTF6fLryb26vHl3NEmh38/EU0t1FZa6Zxy LluV7yUBConqFNYDhbhcrDZ4dwq4Iu5yMhmezPMSC+dO2VrRhhimMt35kPLa+4Af2orX W4HXv3gC39JpN/K3Joh1kvum/4BmQ1uQWXV8MibHgyE8KzPxBmj++HZZH8yCTTdjGZMh Atnm8AhH0GDdDXZL4VHVBrJTKZLxED3UwuN5Uph2s3435PPsCHBC/VIp1HHv6SWCGhEj lzoPIaYvQk5iuviM+hmQKJp5b/0elTFbeQo7t/zw/bAcXSTJ3i3sCNps819Ys182fp5P zFyw== X-Gm-Message-State: AJIora8+dioBtnM/BvSzEaJRBPnL9B/bpy2rO4rrfrkPkF6gRL2+FYKW 1Mw8yGFwXUHY9pbS04tHAK65pBqACe6Q2EuNQPA= X-Google-Smtp-Source: AGRyM1uBY40zRdiXvz/dLsOevnEOOQ6LuvMbENYGT0i6PdItdg98J0UJoi7msjaAYmG930fCtoDv7co14cSPH61FdAw= X-Received: by 2002:a17:906:7310:b0:72f:cad0:d436 with SMTP id di16-20020a170906731000b0072fcad0d436mr6412144ejc.751.1659192515398; Sat, 30 Jul 2022 07:48:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 30 Jul 2022 15:48:23 +0100 Message-ID: To: Nikita Popov Cc: juan carlos morales , PHP internals Content-Type: multipart/alternative; boundary="0000000000007e901805e506dcec" Subject: Re: [PHP-DEV] RFC Idea - is_json - looking for feedback From: davidgebler@gmail.com (David Gebler) --0000000000007e901805e506dcec Content-Type: text/plain; charset="UTF-8" On Sat, Jul 30, 2022 at 3:01 PM Nikita Popov wrote: > On Fri, Jul 29, 2022 at 4:27 PM juan carlos morales < > dev.juan.morales@gmail.com> wrote: > > > I am following the RFC guideline for the first time. ( > > https://wiki.php.net/rfc/howto) > > > > As suggested there, I am here to get a feeling from you, regarding the > > following RFC for PHP. > > > > # Change (draft): > > > > New function in php called like: > > > > is_json(string $string): bool > > > > ## Description > > ### Parameters > > string $string -> string to find out if is a valid JSON or not > > > > ### Return > > Returns a bool. The function is capable to determine if the passed string > > is a valid JSON (true) or not (false). > > > > # Why this function ? > > > > At the moment the only way to determine if a JSON-string is valid we have > > to execute the json_decode() function. > > > > The drawback about this, is that json_decode() generates an in memory an > > object/array (depending on parameters) while parsing the string; this > leads > > to a memory usage that is not needed (because we use memory for creating > > the object/array) and also can cause an error for reaching the > memory-limit > > of the php process. > In the last 15 years, the only time I've ever needed to know if a string is valid JSON is if I'm about to decode or otherwise parse it as JSON. If I'm decoding what I expect to be a large JSON blob, such that memory usage might be a concern, personally I use https://github.com/salsify/jsonstreamingparser but the point is userland solutions are possible. What I'm asking is what's the practical use for this proposed function? Where are you likely to need to know if a string is valid JSON but not have to (try to, with error handling) parse it almost immediately afterwards anyway? Unless there is some fairly commonplace use case for this I'm not thinking of, you're going to be using that extra memory, or using a streaming parser, at some point in your script regardless. If there is genuine demand for it, I'd be in favour (I'm not a voting member so kind of moot but...), otherwise I'm generally against introducing new core functions which are either edge-case or can be perfectly well dealt with via userland code. Cheers -Dave > > > > Sometimes we just need to know is the string is a valid json or not, and > > nothing else. > > > > # Do we need something like this? If a check to an string is valid JSON > > then for sure I will have to use it in my code either as an object or an > > array. > > > > Well that is not true. There are plenty of cases where you just need to > > check if a string is a valid json and that is it. Just looking into > > stackoverflow will give you an idea about how many people is looking for > > something like this in an efficient way. > > > > Could you please give some specific examples where the proposed > functionality would be useful? > > Regards, > Nikita > --0000000000007e901805e506dcec--