Skip to content

Commit 8ac1afc

Browse files
Fixed formatting
1 parent 4693eec commit 8ac1afc

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ Result:
319319
### Change key case
320320

321321
```php
322-
use DragonCode\Contracts\Pretty\Arr\Caseable;use DragonCode\PrettyArray\Services\Formatter;
322+
use DragonCode\Contracts\Pretty\Arr\Caseable;
323+
use DragonCode\PrettyArray\Services\Formatter;
323324

324325
$service = Formatter::make();
325326
$service->setCase(Caseable::PASCAL_CASE);
@@ -363,7 +364,8 @@ The following options are available:
363364
### Storing file
364365

365366
```php
366-
use DragonCode\PrettyArray\Services\File;use DragonCode\PrettyArray\Services\Formatter;
367+
use DragonCode\PrettyArray\Services\File;
368+
use DragonCode\PrettyArray\Services\Formatter;
367369

368370
$service = Formatter::make();
369371

@@ -397,6 +399,44 @@ return [
397399
];
398400
```
399401

402+
#### As JSON
403+
404+
```php
405+
use DragonCode\PrettyArray\Services\File;
406+
use DragonCode\PrettyArray\Services\Formatter;
407+
408+
$service = Formatter::make();
409+
410+
$service->asJson();
411+
412+
$formatted = $service->raw($array);
413+
414+
File::make($formatted)
415+
->store('foo.json');
416+
```
417+
418+
Result in stored file `foo.json`:
419+
420+
```json
421+
{
422+
"foo": 1,
423+
"bar": 2,
424+
"baz": 3,
425+
"qwerty": "qaz",
426+
"baq": {
427+
"0": "qwe",
428+
"1": "rty",
429+
"asd": "zxc"
430+
},
431+
"asdfgh": {
432+
"foobarbaz": "qwe",
433+
"2": "rty",
434+
"qawsed": "zxc"
435+
},
436+
"2": "'iop'"
437+
}
438+
```
439+
400440
## License
401441

402442
This package is licensed under the [MIT License](LICENSE).

src/Services/Formatters/Json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function value($value): mixed
6262
return $this->prepare($value);
6363
}
6464

65-
return $this->castValue($value);
65+
return $value;
6666
}
6767

6868
protected function encode(mixed $value): string

tests/stubs/json.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
"foo": 1,
33
"bar": 2,
44
"baz": 3,
5-
"qwe rty": "'qaz'",
5+
"qwe rty": "qaz",
66
"baq": {
7-
"0": "'qwe'",
8-
"1": "'rty'",
9-
"asd": "'zxc'"
7+
"0": "qwe",
8+
"1": "rty",
9+
"asd": "zxc"
1010
},
1111
"asd fgh": {
12-
"foo bar baz": "'qwe'",
13-
"2": "'rty'",
14-
"qaw sed": "'zxc'"
12+
"foo bar baz": "qwe",
13+
"2": "rty",
14+
"qaw sed": "zxc"
1515
},
16-
"2": "'iop'"
16+
"2": "iop"
1717
}

0 commit comments

Comments
 (0)