PHPackages                             pwm/jgami - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. pwm/jgami

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

pwm/jgami
=========

Map functions over JSON.

0.5.0(7y ago)3180MITPHPPHP &gt;=7.2.0

Since Oct 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/pwm/jgami)[ Packagist](https://packagist.org/packages/pwm/jgami)[ Docs](https://github.com/pwm/jgami)[ RSS](/packages/pwm-jgami/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (6)Used By (0)

JGami
=====

[](#jgami)

[![Build Status](https://camo.githubusercontent.com/44fd62c0ad4357afca54e453a2475bb50d74616af233356ac37348dfa3dff291/68747470733a2f2f7472617669732d63692e6f72672f70776d2f6a67616d692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pwm/jgami)[![codecov](https://camo.githubusercontent.com/9ebe25b8494a81114b52393defe3044addc751d365324ab8100fe8181150922a/68747470733a2f2f636f6465636f762e696f2f67682f70776d2f6a67616d692f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/pwm/jgami)[![Test Coverage](https://camo.githubusercontent.com/af12a935f7a8f90555a89afe574f316104a2ed287e032a6991bdae011da90996/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f39346635626235303733646339303262353437662f746573745f636f766572616765)](https://codeclimate.com/github/pwm/jgami/test_coverage)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

Have you ever mapped a function over a list? Now you can do the same with JSON!

JGami provides a simple API to update values in arbitrarily complex JSON structures while preserving structural integrity.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [How it works](#how-it-works)
- [Tests](#tests)
- [Changelog](#changelog)
- [Licence](#licence)

Requirements
------------

[](#requirements)

PHP 7.2+

Installation
------------

[](#installation)

```
$ composer require pwm/jgami

```

Usage
-----

[](#usage)

It's probably easiest to dive straight into some sample code. We will update some JSON data to our liking by mapping a function over it:

```
// What we have
$json = '{
    "name": "Alice",
    "age": 27,
    "likes": [
        "Types",
        "Graphs",
        "Nature"
    ],
    "job": {
        "title": "Developer",
        "company": "Acme Corp."
    },
    "pets": [
        {
            "name": ["Woof"],
            "type": "Dog"
        },
        {
            "name": ["Mr. Grumpy", "Mrs. Grumpy"],
            "type": "Cat"
        }
    ]
}';

// What we want
$expectedJson = '{
    "name": "Alice Wonderland",
    "age": 37,
    "likes": [
        "Types",
        "Trees",
        "Nature"
    ],
    "job": {
        "title": "Developer",
        "company": "Acme Corp."
    },
    "pets": [
        {
            "name": ["Woof
