cwola/jsonc

提供Jsonc(带注释的JSON)解析器。

v1.0.1 2022-07-10 04:47 UTC

This package is auto-updated.

Last update: 2024-09-12 05:00:34 UTC


README

PHP JSON with Comments(Cwola库)。

概述

为PHP提供JSONC(带注释的JSON)解析器。

要求

  • PHP8.0+

安装

composer require cwola/jsonc

使用方法

<?php

$value = <<< JSONC
/**
 * JSON with Comments for PHP.
 * DOC BLOCK.
 */

// Line comment.

{
    "id": "xxx",  // Identify
    "name": "jhon doe"  // your name
    "age": 0,
    "keyword": [
        "xxx", 1, -5
    ]
}
JSONC;

$json = Cwola\Jsonc\decode($value);
echo $json['name'];  // jhon doe

echo Cwola\Jsonc\toJson($value);  // output json string

echo Cwola\Jsonc\toXml($value);  // output xml string

echo Cwola\Jsonc\toReadableAST($value);  // output Abstract Syntax Tree

许可

MIT