Coder Social home page Coder Social logo

laminas / laminas-json Goto Github PK

View Code? Open in Web Editor NEW
35.0 17.0 9.0 2.08 MB

provides convenience methods for serializing native PHP to JSON and decoding JSON to native PHP

Home Page: https://docs.laminas.dev/laminas-json/

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%
json

laminas-json's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laminas-json's Issues

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


Originally posted by @27cm at zendframework/zend-json#27

Psalm integration

Feature Request

Q A
QA yes

Summary

As decided during the Technical-Steering-Committee Meeting on August 3rd, 2020, Laminas wants to implement vimeo/psalm in all packages.

Implementing psalm is quite easy.

Required

  • Create a .psalm.xml.dist in the project root
  • Copy and paste the contents from this psalm.xml.dist
  • Run $ composer require vimeo/psalm
  • Run $ vendor/bin/psalm --set-baseline=psalm-baseline.xml
  • Add a composer script static-analysis with the command psalm --shepherd --stats
  • Add a new line to script: in .travis.yml: - if [[ $TEST_COVERAGE == 'true' ]]; then composer static-analysis ; fi
  • Remove phpstan from the project (phpstan.neon.dist, .travis.yml entry, composer.json require-dev and scripts)
Optional
  • Fix as many psalm errors as possible.

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().


Originally posted by @Hoszi at zendframework/zend-json#31

PHP 8.0 support

Feature Request

Q A
New Feature yes

Summary

To be prepared for the december release of PHP 8.0, this repository has some additional TODOs to be tested against the new major version.

In order to make this repository compatible, one has to follow these steps:

  • Modify composer.json to provide support for PHP 8.0 by adding the constraint ~8.0.0
  • Modify composer.json to drop support for PHP less than 7.3
  • Modify composer.json to implement phpunit 9.3 which supports PHP 7.3+
  • Modify .travis.yml to ignore platform requirements when installing composer dependencies (simply add --ignore-platform-reqs to COMPOSER_ARGS env variable)
  • Modify .travis.yml to add PHP 8.0 to the matrix (NOTE: Do not allow failures as PHP 8.0 has a feature freeze since 2020-08-04!)
  • Modify source code in case there are incompatibilities with PHP 8.0

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


Originally posted by @JohnWhitleyEkkoSense at zendframework/zend-json#47

Issues while upgrating the zend to laminus my laravel php is 5.2 i am trying to upgrade to 8.x

I am facing the issue while trying to upgrade the laravel can some make a lover it.

laminas/laminas-json[2.0.3, ..., 2.6.1, 3.0.0, ..., 3.1.2] require laminas/laminas-zendframework-bridge ^1.0 ->
found laminas/laminas-zendframework-bridge[1.0.0, ..., 1.2.1] but these were not loaded, likely because it conflicts with another require.
- laminas/laminas-validator[2.12.0, ..., 2.13.0] require laminas/laminas-zendframework-bridge ^1.0 -> found laminas/laminas-zendframework-bridge[1.0.0, ..., 1.2.1] but these were not loaded, likely because it conflicts with another
require.
- davibennun/laravel-push-notification dev-laravel5 requires sly/notification-pusher 2.* -> satisfiable by sly/notification-pusher[v2.0, ..., v2.3.7].
- sly/notification-pusher[v2.3.5, ..., v2.3.6] require zendframework/zendservice-google-gcm ~2.0 -> satisfiable by zendframework/zendservice-google-gcm[2.0.0, 2.1.0, 2.1.1].
- sly/notification-pusher[v2.2.14, ..., v2.3.4] require zendframework/zendservice-google-gcm 2.* -> satisfiable by zendframework/zendservice-google-gcm[2.0.0, 2.1.0, 2.1.1].
- sly/notification-pusher[v2.0, ..., v2.2.13] require zendframework/zendservice-google-gcm 1.* -> satisfiable by zendframework/zendservice-google-gcm[1.0.0, 1.0.1, 1.0.2, 1.0.3].
- zendframework/zendservice-google-gcm[2.0.0, ..., 2.1.0] require zendframework/zend-json ^2.0 -> satisfiable by laminas/laminas-json[2.0.3, ..., 2.6.1].
- zendframework/zendservice-google-gcm 2.1.1 requires zendframework/zend-json ^2.0 || ^3.0 -> satisfiable by laminas/laminas-json[2.0.3, ..., 2.6.1, 3.0.0, 3.1.0, 3.1.1, 3.1.2].
- zendframework/zendservice-google-gcm[1.0.0, ..., 1.0.3] require zendframework/zend-json >=2.0.0 -> satisfiable by laminas/laminas-json[2.0.3, ..., 2.6.1, 3.0.0, 3.1.0, 3.1.1, 3.1.2].
- sly/notification-pusher v2.3.7 requires zendframework/zend-validator ^2.12 -> satisfiable by laminas/laminas-validator[2.12.0, 2.12.1, 2.12.2, 2.13.0].
- Root composer.json requires davibennun/laravel-push-notification dev-laravel5 -> satisfiable by davibennun/laravel-push-notification[dev-laravel5]

Thanks in advance when we were trying to composer update we are facing this issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.