cmpayments/jsonlint 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cmpayments/jsonlint

Composer 安装命令:

composer require cmpayments/jsonlint

包简介

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JS

README 文档

README

License Latest Stable Version Scrutinizer Code Quality Total Downloads Reference Status

JSON Lint for PHP checks a string for invalid or malformed JSON, control character error, incorrect encoding or just plain old syntax errors. It returns comprehensive feedback in a one-line error message (one-line message especially meant for REST APIs) about the first error that occurred in the (JSON) string. It supports both RFC 4627 and (its superseding) RFC 7159.

Usage

use CMPayments\JsonLint\JsonLinter;

$linter = new JsonLinter();

// example JSON
$json = '{
    "id": 2,
    "name": "JSON Parser test",
    \'dimensions\': {
        "length": 7.0,
        "width": 12.0,
        "height": 9.5
    }
}';

// returns null if it's valid json, or a ParseException object.
$result = $linter->lint($json);

// Call $result->getMessage() on the ParseException object to get a well formatted error message error like this:
// You used single quotes instead of double quotes on string 'dimensions' on line 4 at column 9. It appears you have an extra trailing comma

// Call $result->getDetails() on the exception to get more info.
$result->getDetails();

// $result->getDetails() returns;
array (size=6)
  'errorCode' => int 3
  'match' => string 'dimensions' (length=10)
  'token' => string 'INVALID' (length=7)
  'line' => int 3
  'column' => int 9
  'expected' =>
    array (size=1)
      0 => string 'STRING' (length=6)

Installation

For a quick install with Composer use:

$ composer require cmpayments/jsonlint

JSON Lint for PHP can easily be used within another app if you have a PSR-4 autoloader, or it can be installed through Composer.

Requirements

  • PHP 5.4+
  • [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Todo

  • Add support for keys without double quotes*

*RFC 4627 states that an object is an unordered collection of zero or more key/value pairs, where a key is a string and a value is a string, number, boolean, null, object, or array. This JSON linter tends to be more lenient towards keys without quotes in order to accept request from a JavaScript frontend.

Author

Boy Wijnmaalen - boy.wijnmaalen@cmtelecom.com - https://twitter.com/boywijnmaalen

License

JSON Lint is licensed under the MIT License - see the LICENSE file for details

Acknowledgements

This library is based on Seldaek/jsonlint and zaach/jsonlint.

统计信息

  • 总下载量: 4.72k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 59
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固