承接 bitwerft/json-include 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

bitwerft/json-include

最新稳定版本:1.0.0

Composer 安装命令:

composer require bitwerft/json-include

包简介

Provides functionality to include content of JSON files into another JSON files.

README 文档

README

This allows you to use #include within .json files, so you can break up large json files into multiple smaller ones.

Installation

Through composer:

  • Simply execute composer require bitwerft/json-include

Usage

1. JSON File

  • In your json file add a "#include" as the key, with the name (if in the same folder) or the path to the file as the value
  • This can be in the middle of an array, as the only array element or nested deep in the file. The content of the included json will be placed at the exact same place.
  • This file needs to be a valid json
  • There is a maximum Number of includes, which is by default set to 100 to prevent circular includes
  • use Bitwerft\JsonInclude\JsonInclude;
  • Execute using JsonInclude::render('filename.json');

2. Included JSON Files

  • The included files need to be valid json themselves
  • They don't need to have the .json file extension
  • Every file can be included multiple times
  • They can also have "#include"s, which will be included recursivly
  • Circular includes will cause an error

3. Result

  • The assembled json will be returned as an unformatted string
  • By default if any include fails, an Exception containing all info will be thrown
  • The last used info array can also be accesed through JsonInlude::$info

Example

  1. JSON File
{
    "text": [
        {"#include":"http://example.com/file.json"}
    ],
    
    "#include":"file:///storage/app/file2.json"
}
  1. JSON Include 1 (http://example.com/file.json)
{
    "paragraph1": {
        "sentence": "Lorem ipsum"
    },
    "paragraph2": {
        "sentence": "dolor sit amet"
    }
}
  1. JSON Include 2 (file:///storage/app/file2.json)
{
"ids": [1, 2, 3, 4, 5]
}
  1. Result (with added formatting)
{
    "text":[
        {
            "paragraph1": {
                "sentence":"Lorem ipsum"
            },

            "paragraph2": {
                "sentence":"dolor sit amet"
            }
        }
    ],
    "ids": [1,2,3,4,5]
}

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-18