All Projects → adhocore → php-json-fixer

adhocore / php-json-fixer

Licence: MIT license
Fix truncated JSON data

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-json-fixer

php-underscore
PHP underscore inspired &/or cloned from _.js, with extra goodies like higher order messaging
Stars: ✭ 42 (+13.51%)
Mutual labels:  adhocore, hacktoberfest2021
php-env
A small and fast .env loader for PHP
Stars: ✭ 19 (-48.65%)
Mutual labels:  adhocore, hacktoberfest2021
php-cron-expr
Ultra lightweight, Dependency free and Super Fast Cron Expression parser for PHP
Stars: ✭ 42 (+13.51%)
Mutual labels:  adhocore, hacktoberfest2021
Hacktoberfest2021
This is for Hacktoberfest 2021
Stars: ✭ 16 (-56.76%)
Mutual labels:  hacktoberfest2021
Androapps
Important Android projects to learn fundamentals of android development
Stars: ✭ 48 (+29.73%)
Mutual labels:  hacktoberfest2021
HacktoberFest21
A beginner friendly repository for HacktoberFest 2021
Stars: ✭ 45 (+21.62%)
Mutual labels:  hacktoberfest2021
HacktoberFest-2021
A repository for Hacktober Fest contributions. Everyone is welcome. Fork away!
Stars: ✭ 10 (-72.97%)
Mutual labels:  hacktoberfest2021
keycloak-admin-client
PHP Client to connect to Keycloak admin rest apis
Stars: ✭ 57 (+54.05%)
Mutual labels:  hacktoberfest2021
College-Notes
Contribute your handwritten PDF notes and help other students ✌ #DecodersCommunity 🖤
Stars: ✭ 30 (-18.92%)
Mutual labels:  hacktoberfest2021
HacktoSearch
Helping you find the best contributions you can make in Hacktoberfest 2021!
Stars: ✭ 17 (-54.05%)
Mutual labels:  hacktoberfest2021
VSCode-Bedrock-Development-Extension
An extension that provides support for files such as: .mcfunction, .json and .lang. Features include: completion, validations, formatters, diagnostics, cheat-sheets, code-actions, generation of files, and development tools to help develop Minecraft Bedrock Addons or Minecraft Education Edition.
Stars: ✭ 45 (+21.62%)
Mutual labels:  hacktoberfest2021
jbehave-junit-runner
Integrate JBehave better with JUnit. Reports all Stories, Scenarios and Steps as JUnit Suites and Test Cases.
Stars: ✭ 70 (+89.19%)
Mutual labels:  hacktoberfest2021
macropower-analytics-panel
It's like Google Analytics, but for Grafana dashboards!
Stars: ✭ 16 (-56.76%)
Mutual labels:  hacktoberfest2021
Commandline-Games-hacktoberfest
A repository to share command line games. An opportunity to start and learn about open source code contributions flow.
Stars: ✭ 16 (-56.76%)
Mutual labels:  hacktoberfest2021
opensource
Site de Open Source da CodeMiner42
Stars: ✭ 25 (-32.43%)
Mutual labels:  hacktoberfest2021
Fenice-Network
Building the job search portal which helps both recruiters and job seekers to get perfect jobs.
Stars: ✭ 20 (-45.95%)
Mutual labels:  hacktoberfest2021
HacktoberFest2021
No description or website provided.
Stars: ✭ 33 (-10.81%)
Mutual labels:  hacktoberfest2021
rePocketable
Tool to fetch articles from (getPocket|the web) and turn them into epub
Stars: ✭ 49 (+32.43%)
Mutual labels:  hacktoberfest2021
Hacktoberfest-2021
❗❗ Make your first PR now, accepting and merging PRs continuously. ⭐HACKTOBER ACCEPTED 2021 ✨✨Happy Hacking 💖💖
Stars: ✭ 11 (-70.27%)
Mutual labels:  hacktoberfest2021
open-climate-investing
Application and data for analyzing and structuring portfolios for climate investing.
Stars: ✭ 20 (-45.95%)
Mutual labels:  hacktoberfest2021

adhocore/json-fixer

PHP library to fix Truncated JSON data by padding contextual counterpart to the end. Works with PHP5.4 or above.

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License Donate 15 Donate 25 Donate 50 Tweet

It is a work in progress and might not cover all edge cases. It would be great if you try it out, open some issues or contribute.

Installation

composer require adhocore/json-fixer

Usage

use Ahc\Json\Fixer;

$json = (new Fixer)->fix('{"a":1,"b":2');
// {"a":1,"b":2}

$json = (new Fixer)->fix('{"a":1,"b":true,');
// {"a":1,"b":true}

$json = (new Fixer)->fix('{"b":[1,[{"b":1,"c"');
// {"b":[1,[{"b":1,"c":null}]]}

// For batch fixing, you can just reuse same fixer instance:
$fixer = new Fixer;

$fixer->fix('...');
$fixer->fix('...');
// ...

Error

If there's error and fixer cant fix the JSON for some reason, it will throw a RuntimeException. You can disable this behavior by passing silent flag (2nd param) to fix() in which case original input is returned:

(new Fixer)->silent()->fix('invalid');
// 'invalid'

(new Fixer)->silent(true)->fix('invalid');
// 'invalid'

(new Fixer)->silent(false)->fix('invalid');
// RuntimeException

Missing Value

By default missing values are padded with null. You can change it passing desired value to missingValue():

// key b is missing value and is padded with `null`
$json = (new Fixer)->fix('{"a":1,"b":');
// {"a":1,"b":null}

// key b is missing value and is padded with `true`
$json = (new Fixer)->missingValue(true)->fix('{"a":1,"b":');
// {"a":1,"b":true}

// key b is missing value and is padded with `"truncated"`
// Note that you can actually inject a whole new JSON subset as 3rd param
// but that should be a valid JSON segment and is not checked by fixer.
$json = (new Fixer)->missingValue('"truncated"')->fix('{"a":1,"b":');
// {"a":1,"b":"truncated"}

Todo

  • Configurable missing value as per context (options)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].