<commit_before># SlimJson [![Latest Stable Version](https://poser.pugx.org/dogancelik/slim-json/v/stable.png)](https://packagist.org/packages/dogancelik/slim-json)
SlimJson is an easy-to-use and advanced JSON middleware for Slim PHP framework. SlimJson helps you write web apps that return JSON output.

## How to install
You can install SlimJson with Composer by:
```
composer install dogancelik/slim-json
```
or adding this line to your `composer.json` file:
```
"dogancelik/slim-json": "dev-master"
```

## How to use
```php
require 'vendor/autoload.php';
$app = new \Slim\Slim();

// Add the middleware globally
$app->add(new \SlimJson\Middleware(array(
  'json.status' => true,
  'json.override_error' => true
)));

$app->get('/', function() use ($app) {
  $app->render(200, ['Hello' => 'World']);
});

$app->get('/error', function() use ($app)) {
  throw new \Exception('This is an error');
});

$app->run();
```

If you go to `localhost/`, you will get: `{"Hello": "World", "_status": 200}`

If you go to `localhost/error`: `{"error": "This is an error", "_status": 500}`

If you go to `localhost/notfound`: `{"error": "'/notfound' is not found.", "_status": 404}`

### Rendering JSON
If you haven't noticed, I didn't add a JSON view to our Slim app.
It's because when you add the middleware, we add the JSON view for you so you don't have to.

You should see that we are using a different `$app->render()` method here.

Rendering parameters are these: `function render(status, data)`
<commit_msg>Fix in... :pensive: README<commit_after># SlimJson [![Latest Stable Version](https://poser.pugx.org/dogancelik/slim-json/v/stable.png)](https://packagist.org/packages/dogancelik/slim-json)
SlimJson is an easy-to-use and advanced JSON middleware for Slim PHP framework. SlimJson helps you write web apps that return JSON output.

## How to install
You can install SlimJson with Composer by:
```
composer install dogancelik/slim-json
```
or adding this line to your `composer.json` file:
```
"dogancelik/slim-json": "dev-master"
```

## How to use
```php
require 'vendor/autoload.php';
$app = new \Slim\Slim();

// Add the middleware globally
$app->add(new \SlimJson\Middleware(array(
  'json.status' => true,
  'json.override_error' => true,
  'json.override_notfound' => true
)));

$app->get('/', function() use ($app) {
  $app->render(200, ['Hello' => 'World']);
});

$app->get('/error', function() use ($app)) {
  throw new \Exception('This is an error');
});

$app->run();
```

If you go to `localhost/`, you will get: `{"Hello": "World", "_status": 200}`

If you go to `localhost/error`: `{"error": "This is an error", "_status": 500}`

If you go to `localhost/notfound`: `{"error": "'/notfound' is not found.", "_status": 404}`

### Rendering JSON
If you haven't noticed, I didn't add a JSON view to our Slim app.
It's because when you add the middleware, we add the JSON view for you so you don't have to.

You should see that we are using a different `$app->render()` method here.

Rendering parameters are these: `function render(status, data)`

{'fraction_non_alphanumeric': 0.16912005233889435, 'fraction_numerical': 0.007850834151128557, 'mean_word_length': 4.549909255898367, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6041993', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1009, 'n_words': 359}