PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStar 37%Total: 367 This week: 1All time: 6,840 This week: 571Up
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: 4 packages by
Country: Russian Federation Russian Federation
Age: 47
All time rank: 301983 in Russian Federation Russian Federation
Week rank: 50 Up3 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  
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  /  src  
File Role Description
Files folder imagealexstar (1 file)

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:367
This week:1
All time:6,840
This week:571Up
User Ratings User Comments (1)
 All time
Utility:55%StarStarStar
Consistency:55%StarStarStar
Documentation:40%StarStarStar
Examples:-
Tests:-
Videos:-
Overall:37%StarStar
Rank:3959
 
Could not make anything out of it.
6 years ago (Alekos Psimikakis)
5%Star