PHP Classes

PHP Ignore JSON Key: Remove certain key values from JSON strings

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
StarStarStar 52%Total: 254 All time: 7,873 This week: 560Up
Version License PHP version Categories
json-key-ignorer 1.0.0Freely Distributable5PHP 5, Data types, Parsers
Description 

Author

This class can remove certain key values from JSON strings.

It takes a JSON encoded string and parses it to remove object keys with names passed in an array.

The class returns another JSON string with the specified key removed.

Innovation Award
PHP Programming Innovation award nominee
September 2016
Number 13
JSON is nowadays used by many applications and APIs to exchange data in a format that can be supported by many languages.

Sometimes you need to do some processing to filter unwanted entries in JSON data structure. Usually you would use json_decode parse the data, traverse the parsed data and filter the unwanted information, and regenerate it with json_encode.

This class offers a simpler solution. It can take a JSON string and removed the unwanted entries from the JSON string directly.

This way you do not need to perform traversal of data and custom processing to remove the unwanted data.

Manuel Lemos
Picture of Janjan
  Performance   Level  
Name: Janjan <contact>
Classes: 1 package by
Country: Philippines Philippines
Innovation award
Innovation award
Nominee: 1x

Example

<?php
require_once('ignore.php');
$ignore = new Ignore;

$val = '{\"message\":\"Password updated successfullyasd\",\"name\":\"Stephen\",\"email\":\"steph5592044d70ff9@gmail.com\",\"username\":\"steph5592044d70ff9\",\"status\":\"1\",\"api_key\":\"d738f1c6cc88b8b6d2dcbb9c964b08b2\",\"error\":0,\"message\":\"You are successfully registered\"}';

$exclude = "api_key, email, username";

echo
$ignore->ignore_keys($val, $exclude);


?>


Details

Ignore Key class does something in json you string that you don't need to get them parsed. This is good for api developers if you have raw data and you want to ignore some keys at the same time, not compromising the server's performance since it is using string manipulation to ignore the keys you want.

  Files folder image Files (3)  
File Role Description
Plain text file ignore.php Class ignore class
Accessible without login Plain text file index.php Example index file to access the class
Accessible without login Plain text file README.md Doc. documentation

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  
 0%
Total:254
This week:0
All time:7,873
This week:560Up
 User Ratings  
 
 All time
Utility:65%StarStarStarStar
Consistency:60%StarStarStarStar
Documentation:70%StarStarStarStar
Examples:70%StarStarStarStar
Tests:-
Videos:-
Overall:52%StarStarStar
Rank:2350