PHP Classes

PHP JSON Maker: Create and edit JSON data setting class variables

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 37%Total: 367 All time: 6,841 This week: 673Up
Version License PHP version Categories
jsonmaker 1.1.0Custom (specified...5.4PHP 5, Text processing, Data types
Description 

Author

This class can be used to create and edit JSON data setting class variables.

It can compose JSON data structures by setting class objects variables.

Evaluating the object will return the whole data structured encoded as JSON.

Innovation Award
PHP Programming Innovation award nominee
August 2017
Number 2


Prize: SourceGuarding PHP encoder tool
JSON is nowadays very common format to store typed information in strings.

When you have a complex object structure, usually it is necessary to create the top level object and each child object one by one.

This package makes that task simpler by allowing to create multiple nested objects using a single command.

Manuel Lemos
Picture of Alexey Starikov
  Performance   Level  
Name: Alexey Starikov <contact>
Classes: 3 packages by
Country: Russian Federation Russian Federation
Age: 47
All time rank: 300983 in Russian Federation Russian Federation
Week rank: 178 Up10 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 4x

Example

jsonMaker

Create JSON easy

PHP class for creating and modifying a text string in JSON format

Installation

composer require alexsuperstar/jsonmaker

Creating JSON

$a = new \alexstar\JsonMaker();
$cc='xyz';
$a->{$cc}->bbb->cccc[0]->xxx=5;
$a->{$cc}->zz='qq';
$a->xyz->zf='qq';
$a->xx->zz='qq';
echo $a; 

Result

{"xyz":{"bbb":{"cccc":[{"xxx":5}]},"zz":"qq","zf":"qq"},"xx":{"zz":"qq"}}

Editing JSON

  Original JSON

{
  "firstName": "????",
  "lastName": "??????",
  "address": {
    "streetAddress": "?????????? ?., 101, ??.101",
    "city": "?????????",
    "postalCode": 101101
  },
  "phoneNumbers": [
    "812 123-1234",
    "916 123-4567"
  ]
}

PHP code

<?php 
$loader = require_once __DIR__ . '/vendor/autoload.php';
$json = new \alexstar\JsonMaker('{"firstName":"????","lastName":"??????","address":{"streetAddress":"?????????? ?., 101, ??.101","city":"?????????","postalCode":101101},"phoneNumbers":["812 123-1234","916 123-4567"]}');
$json->firstName='???????';
$dom='???';
$json->address->{$dom}=6;
$json->address->code[]='123';
$json->address->code[]='456';
$json->phoneNumbers[2]='+7(123)1233-45-67';
unset($json->address->city,$json->phoneNumbers[0]);
echo $json;
echo 'code count: ',count($json->address->code);

Result

{
  "firstName": "???????",
  "lastName": "??????",
  "address": {
    "streetAddress": "?????????? ?., 101, ??.101",
    "postalCode": 101101,
    "???": 6,
    "code": [
      "123",
      "456"
    ]
  },
  "phoneNumbers": {
    "1": "916 123-4567",
    "2": "+7(123)1233-45-67"
  }
}
code count: 2

PS: about the use of memory, I can not say anything, like everything is transmitted by links, but I'm not sure.

Translated Google Translate


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.en.md Example Example script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
Files folder imagealexstar (1 file)

  Files folder image Files (5)  /  src  /  alexstar  
File Role Description
  Plain text file JsonMaker.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:367
This week:0
All time:6,841
This week:673Up
User Ratings User Comments (1)
 All time
Utility:55%StarStarStar
Consistency:55%StarStarStar
Documentation:40%StarStarStar
Examples:-
Tests:-
Videos:-
Overall:37%StarStar
Rank:4040
 
Could not make anything out of it.
6 years ago (Alekos Psimikakis)
5%Star