2017 © Pedro Peláez
 

library json-preparator

Prepare JSON with schema

image

kaizer666/json-preparator

Prepare JSON with schema

  • Friday, August 25, 2017
  • by kaizer666
  • Repository
  • 1 Watchers
  • 0 Stars
  • 52 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 6 % Grown

The README.md

JsonPreparator

Russian Readme

Russian Readme is here, (*1)

About

Service for the preparation of JSON according to the proposed scheme. Adds missing elements, removes unnecessary items., (*2)

Install

```$bash composer require kaizer666/json-preparator, (*3)


## Usage ```$php use Json\JsonPreparator; function test() { $require = true; $schema = "/path/to/schema.json"; $data = json_decode('{ "integer_with_def": 2.0002, "float": 123000, "string": "text", "object": {}, "array_string": [ "1.1.1.1.1.1.", "1" ], "array_integer": [ "1.1.1.1.1.", "2.2.2.2." ], "array": [ { "integer_with_def": 1, "float": 1000, "text": "text1" },{ "integer_with_def": 2, "float": 2000, "text": "text2" },{ "integer_with_def": 3, "float": 3000, "text": "text3" },{ "integer_with_def": 4, "float": 4000, "text": "text4" } ] }', true); $preparator = new JsonPreparator($schema, $require); $output = $preparator->prepare($data); return response()->json($output); }

Schema example

```$json { "integer_with_def": { "type": "integer", "default": "32", "require": false }, "integer": { "type": "integer" }, "float": { "type": "float", "format": { "decimals":2, "dec_point":".", "thousands_sep":" " }, "require": false }, "string": { "type":"string" }, "object": { "type":"object", "components": { "integer_with_def": { "type": "integer", "default": "32", "require": false }, "integer": { "type": "integer" }, "float": { "type": "float", "format": { "decimals":2, "dec_point":".", "thousands_sep":" " } } } }, "array_string":{ "type": "array", "values": { "type": "string", "require": false } }, "array_integer":{ "type": "array", "values": { "type": "integer" } }, "array": { "type": "array", "values": { "type": "object", "components": { "integer_with_def": { "type": "integer", "default": "32" }, "integer": { "type": "integer" }, "float": { "type": "float", "format": { "decimals":2, "dec_point":".", "thousands_sep":" " } }, "string": { "type":"string" }, "array_string":{ "type": "array", "values": { "type": "string" } }, "array_integer":{ "type": "array", "values": { "type": "integer" } } } } } }, (*4)


## Field Types
  1. "integer"     - Integer number     - Options:         a) default - the default value if there is no element in the incoming array b) require - a required value
  2. "float"     - A float number     - Options:         a) default - the default value if there is no element in the incoming array         b) format - number format:             - decimals - how many decimal places             - dec_point - decimal separator             - thousands_sep - thousands separator c) require - a required value
  3. "string"     - String     - Options:         a) default - the default value if there is no element in the incoming array b) require - a required value
  4. "object"     - Object {} (associative array)     - Options:         a) components - the list of components of the object b) require - a required value
  5. "array"     - Array []     - Options:         a) values ​​- list of array values b) require - a required value

```, (*5)

The Versions

25/08 2017

dev-master

9999999-dev

Prepare JSON with schema

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Kovalyov Maksim

20/08 2017

0.2

0.2.0.0

Prepare JSON with schema

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Kovalyov Maksim

19/08 2017

0.1

0.1.0.0

Prepare JSON with schema

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Kovalyov Maksim