Json component from Zend Framework

Overview

zend-json

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-json.

Build Status Coverage Status

Zend\Json provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP. For more information on JSON, visit the JSON project site.

Installation

Run the following to install this library:

$ composer require zendframework/zend-json

Documentation

Browse the documentation online at https://docs.zendframework.com/zend-json/

Support

Comments
  • \Zend\Json\Json::prettyPrint fails for json containing string with commas

    \Zend\Json\Json::prettyPrint fails for json containing string with commas

    Having the following JSON:

    { "key" : "Hello, world!" }
    

    and parsing it using

    \Zend\Json\Json::prettyPrint('{ "key" : "Hello, world!" }', ["indent" => ""]);
    

    will produce:

    {"key":"Hello,world!"}
    

    The reason is first line from \Zend\Json\Json::prettyPrint

    $tokens = preg_split('|([\{\}\]\[,])|', $json, -1, PREG_SPLIT_DELIM_CAPTURE);
    

    not taking into account that a comma could resides inside a token.

    bug 
    opened by cezarykluczynski 9
  • Fix: Do not remove space after comma in string value

    Fix: Do not remove space after comma in string value

    This PR

    • [x] asserts that a space after a , in string value is left alone
    • [x] leaves the space after a , in a string value alone

    Fixes #2.

    💁‍♂️ Not sure if a fix yet, but figured I provide a failing test at least.

    bug 
    opened by localheinz 3
  • Fix: Do not print empty arrays and objects with new lines

    Fix: Do not print empty arrays and objects with new lines

    This PR

    • [x] asserts that empty arrays and objects are printed without new lines
    • [x] looks ahead for closing brackets and skips new lines if there's only whitespace in-between
    opened by localheinz 2
  • Check Documentation Code Blocks

    Check Documentation Code Blocks

    Check code blocks are correct

    TLDR; Check in all files that codeblocks are correct, in PSR-2 format and have PHP syntax highlighting applied.

    Code blocks should be in the following format...

    ```php
     'ZEND-FRAMEWORK');
    
    // No required options
    $rendererOptions = array();
    $renderer = Barcode::factory(
        'code39', 'image', $barcodeOptions, $rendererOptions
    );
    
    ```
    

    Note the three backticks then php in the opening fence, and the closing fence is just three backticks. It's common for the opening backticks to have no code type, or something like source.

    Code should also have been automatically formatted into PSR-2 format, but sometimes these slip through the net.

    EasyFix documentation 
    opened by GeeH 2
  • PHP Deprecated:  Array and string offset access syntax with curly braces is deprecated

    PHP Deprecated: Array and string offset access syntax with curly braces is deprecated

    PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in zendframework\zend-json\src\Decoder.php on line 110 PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in zendframework\zend-json\src\Decoder.php on line 365 etc

    enhancement 
    opened by matbech 1
  • Why the public properties aren't get retreived and encoded?

    Why the public properties aren't get retreived and encoded?

    I have a code like this.

    $customer= $this->entityManager->getRepository(Customer::class)->findOneById('5'); $jsonObject = \Zend\Json\Json::encode($customer,true); print_r($jsonObject); die;

    However the output becomes empty/nothing. No errors either from PHP or the ZF3 I can assure, all the data properties of Class Customer are set to public. Where would be the problem?

    opened by razcakappa 1
  • fix for PHP 7.2, 'Object' is a reserved keyword

    fix for PHP 7.2, 'Object' is a reserved keyword

    From Fedora QA: https://apps.fedoraproject.org/koschei/package/php-zendframework-zend-json?collection=f28

    PHPUnit 5.7.23 by Sebastian Bergmann and contributors.
    Runtime:       PHP 7.2.0RC4
    Configuration: /builddir/build/BUILD/zend-json-f42a1588e75c2a3e338cd94c37906231e616daab/phpunit.xml.dist
    ..................................PHP Fatal error:  Cannot use 'Object' as class name as it is reserved in /builddir/build/BUILD/zend-json-f42a1588e75c2a3e338cd94c37906231e616daab/test/TestAsset/Object.php on line 13
    
    
    opened by remicollet 1
  • sql query on encoded json

    sql query on encoded json

    Having issue when query the column contains encoded data however sql query below works fine for encoded data by json_encode func,

    Query SELECT * FROM bidtaxi_master.errorlog WHEREInfoIS NOT NULL and JSON_EXTRACT(Resource, "$.env\'") = "sandbox\'";

    Is there any other sql statement I can use for json query encoded by this component or doctrine?

    invalid 
    opened by ozinal 1
  • Check For Blockquotes In Docs

    Check For Blockquotes In Docs

    Check the document for bad blockquoutes

    TLDR; Check blockquotes are formatted correctly using > and check headings in blockquotes are using ###

    Blockquotes are donated by a single greater than character and then a space. Make sure all the blockquotes in every doc file are correctly formatted. Headings in blockquotes should use ### and not bold.

    Any paragraph spacing in blockquotes should be marked using a single greater than, then a space.

    EasyFix documentation 
    opened by GeeH 1
  • Check Documentation Tables

    Check Documentation Tables

    Check the tables in a document

    TLDR; All tables should be in the format of GHFM using | and - as horizontal and vertical separators respectively

    Check all tables are in the correct format. Please don't use leading and trailing | - more information on github flavoured markdown tables can be found here.

    EasyFix documentation 
    opened by GeeH 1
  • Check Documentation For Other Things

    Check Documentation For Other Things

    Check docs for other problems

    TLDR; Cast your eye over the documetation for any problems not covered in the other issues

    Things slip through the net, so check the documentation for other problems that have been missed. Common other problems include

    • Bullet lists (should be single * then space at the start of line)
    • Inline code - should be marked by three backticks at start and finish
    • bookdown.json file is correctly formated and has the right escaping
    • Links between documentation using RST have been stripped
    • Any other RST has been removed correctly
    • Anything and everything not covered

    If you end up fixing the same problem over and over, please ping Gary Hockin - we may be able to add bespoke issue for that problem, or fix in automated capacity

    EasyFix documentation 
    opened by GeeH 1
  • Adding the new

    Adding the new "forceObject" flag

    Adding the new "forceObject" flag to be passed to the encoder in the options in the manner of ['forceObject' => true,] . This then forces the encoder output to encode to an object rather than an array. This implementation assumes all nested arrays to be forced to be objects in the manner of JSON_FORCE_OBJECT.

    This is the pull request for the conversation outlined in #27

    enhancement 
    opened by JohnWhitleyEkkoSense 2
  • utf8 encoded error

    utf8 encoded error

    there is a problem when json_encode get an incorrect character but i have a solution: in Json.php

    private static function encodeViaPhpBuiltIn($valueToEncode, $prettyPrint = false)
    {
        if (! function_exists('json_encode') || static::$useBuiltinEncoderDecoder === true) {
            return false;
        }
    
        $encodeOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP;
    
        if ($prettyPrint) {
            $encodeOptions |= JSON_PRETTY_PRINT;
        }
        array_walk_recursive($valueToEncode, function(&$item, $key){
            if(!mb_detect_encoding($item, 'utf-8', true)){
                $item = utf8_encode($item);
            }
        });
        $encoded = json_encode($valueToEncode, $encodeOptions | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        return $encoded ? $encoded : json_last_error_msg();
    }
    

    The new section is from array_walk_recursive().

    opened by Hoszi 1
  • Ability to change json_encode() options

    Ability to change json_encode() options

    There is no way to modify json_encode() encode options except JSON_PRETTY_PRINT. For example we can't enable JSON_UNESCAPED_UNICODE or disable default options.

    Extending the base class Zend\Json\Json as workaround creates another problems - can't use JsonRenderer with another Json encoder, Zend\Json\Json only: https://github.com/zendframework/zend-view/blob/master/src/Renderer/JsonRenderer.php#L127-L170

    opened by 27cm 3
  • [Json/Server] Return the invalid parameters list

    [Json/Server] Return the invalid parameters list

    This issue has been moved from the zendframework repository as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html


    Original Issue: https://api.github.com/repos/zendframework/zendframework/issues/7544 User: @dreadnought78 Created On: 2015-05-23T22:04:16Z Updated At: 2015-11-06T23:57:01Z Body If the user forgot or send some required parameter with a wrong name the server returns the error ERROR_INVALID_PARAMS.

    This request added a invalid parameters list in the json response.

    Result before

    {
        "error":{
            "code":-32602,
            "message":"Invalid params",
            "data":null
        },
        "id":"8",
        "jsonrpc":"2.0"
    }
    

    Result after

    {
        "error":{
            "code":-32602,
            "message":"Invalid param(s): [estimatedMonths, location, specieId, coatTypeId]",
            "data":null
        },
        "id":"8",
        "jsonrpc":"2.0"
    }
    

    *Please do not consider this pull request if this implementation has not been made before for security reasons.


    opened by GeeH 1
Releases(release-3.1.2)
  • release-3.1.2(Oct 9, 2019)

    Added

    • Nothing.

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #46 changes curly braces in array and string offset access to square brackets in order to prevent issues under the upcoming PHP 7.4 release.

    • #37 fixes output of \Zend\Json::prettyPrint to not remove spaces after commas in value.

    Source code(tar.gz)
    Source code(zip)
  • release-3.1.1(Jun 18, 2019)

  • release-3.1.0(Jan 4, 2018)

    Added

    • #35 and #39 add support for PHP 7.1 and PHP 7.2.

    Deprecated

    • Nothing.

    Removed

    • #35 removes support for PHP 5.5.

    • #35 removes support for HHVM.

    Fixed

    • #38 provides a fix to Json::prettyPrint() to ensure that empty arrays and objects are printed without newlines.

    • #38 provides a fix to Json::prettyPrint() to remove additional newlines preceding a closing bracket.

    Source code(tar.gz)
    Source code(zip)
  • release-3.0.0(Apr 1, 2016)

    Added

    • #21 adds documentation and publishes it to https://zendframework.github.io/zend-json/

    Deprecated

    • Nothing.

    Removed

    • #20 removes the Zend\Json\Server subcomponent, which has been extracted to zend-json-server. If you use that functionality, install the new component.
    • #21 removes the Zend\Json\Json::fromXml() functionality, which has been extracted to zend-xml2json. If you used this functionality, you will need to install the new package, and rewrite calls to Zend\Json\Json::fromXml() to Zend\Xml2Json\Xml2Json::fromXml().
    • #20 and #21 removes dependencies on zendframework/zendxml, zendframework/zend-stdlib, zendframework/zend-server, and zendframework-zend-http, due to the above listed component extractions.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-2.6.1(Feb 4, 2016)

  • release-2.6.0(Nov 18, 2015)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • #5 removes zendframework/zend-stdlib as a required dependency, marking it instead optional, as it is only used for the Server subcomponent.

      Users of Zend\Json\Server will need to add zendframework/zend-stdlib to their applications in order to use that subcomponent going forward. If you are using that subcomponent, and have determined that zend-stdlib is not installed, you can do so by executing composer require zendframework/zend-stdlib from the command-line.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
Owner
Zend Framework
Zend Framework
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
Db component from Zend Framework

zend-db Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-db. Zend\Db is a component that abstract the access to a Database

Zend Framework 98 Sep 5, 2022
Debug component from Zend Framework

zend-debug Zend\Debug is a component that help the debugging of PHP applications. In particular it offers a static method Zend\Debug\Debug::dump() tha

Zend Framework 12 Jan 29, 2020
Navigation component from Zend Framework

zend-navigation Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-navigation. Zend\Navigation is a component for managing t

Zend Framework 19 Jun 30, 2021
A panel created based on the Zend Framework MVC framework

?? Painel MyZap2.0 Com ZendFramework 3 Descrição Esse é um painel criado como estudo pessoal do framework (Zend Framework MVC) não foi criado para fin

Jonathan Henrique 9 Jun 10, 2022
zend-memory manages data in an environment with limited memory

Memory objects (memory containers) are generated by the memory manager, and transparently swapped/loaded when required.

Zend Framework 16 Aug 29, 2020
Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

zhixin 2 Sep 9, 2022
Json-normalizer: Provides generic and vendor-specific normalizers for normalizing JSON documents

json-normalizer Provides generic and vendor-specific normalizers for normalizing JSON documents. Installation Run $ composer require ergebnis/json-nor

null 64 Dec 31, 2022
PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data

PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data PDF ENGINE VERSION: development: This is a prerelease version

Ajous Solutions 2 Dec 30, 2022
Very easy to use a current limiting component, the code is very simple, based on the webman framework.

Very easy to use a current limiting component, the code is very simple, based on the webman framework.

nsp-team 13 Dec 29, 2022
Iranian wallet provider's integration component for Laravel Framework

Iranian Wallets Integration Component For Laravel Iranian Wallet provider integration handler for Laravel 8.1+ known as LaraWallet component completel

PHP Monsters 11 Dec 26, 2022
JSON Lint for PHP

JSON Lint Usage use Seld\JsonLint\JsonParser; $parser = new JsonParser(); // returns null if it's valid json, or a ParsingException object. $parser-

Jordi Boggiano 1.3k Dec 26, 2022
The easiest way to match data structures like JSON/PlainText/XML against readable patterns. Sandbox:

PHP Matcher Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns. API: PHPMatcher::match($value = '{"foo": "bar"}', $p

Coduo 774 Dec 31, 2022
Simple game server with php without socket programming. Uses the Api request post(json).

QMA server Simple game server with php without socket programming. Uses the Api request post(json). What does this code do? Register the user as a gue

reza malekpour 3 Sep 4, 2021
It's MX Player API gives All Content in JSON format

?? MXPlayer API ?? ?? MXPlayer API Can get Streaming URLs and Other Data in JSON Format From mxplayer.in links for Streaming ?? How to Use : ?? Method

Techie Sneh 8 Nov 30, 2021
JSON schema models and generated code to validate and handle various data in PocketMine-MP

DataModels JSON schema models and generated code to validate and handle various data in PocketMine-MP This library uses php-json-schema-model-generato

PMMP 2 Nov 9, 2022
Simple user settings facade for Hyperf. Settings are stored as JSON in a single database column, so you can easily add it to an existing table.

hyperf-user-settings Simple user settings util for hyperf Settings are stored as JSON in a single database column, so you can easily add it to an exis

lysice 1 Oct 15, 2021
Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API.

Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API. Check out the latest API documentation. Add library in a composer.json file.

Patrick Falize 6 Oct 7, 2021
Here is an Instagram Guest API. Gather all public information as JSON format without logging yourself.

Here is an Instagram Guest API. Gather all public information as JSON format without logging yourself. It's all automation and time saving.

Quatrecentquatre 1 Nov 2, 2021