JsonConverter
in package
Converts and store tabular data into a JSON string.
Tags
Table of Contents
Properties
- $chunkSize : int<1, max>
- $depth : int<1, max>
- $flags : int
- $format : JsonFormat
- $formatter : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null
- $indentSize : int<1, max>
- $emptyIterable : string
- $end : string
- $indentation : non-empty-string
- $indentationLevels : array<string|int, string>
- $jsonEncodeChunk : callable(array<int, T>): string
- $separator : string
- $start : string
Methods
- __call() : self|bool
- __construct() : mixed
- addFlags() : self
- Adds a list of JSON flags.
- chunkSize() : self
- Set the indentation size.
- convert() : Iterator<string|int, string>
- Returns an Iterator that you can iterate to generate the actual JSON string representation.
- create() : self
- DEPRECATION WARNING! This method will be removed in the next major point release.
- depth() : self
- Set the depth of Json encoding.
- download() : int
- Sends and makes the JSON structure downloadable via HTTP.
- encode() : string
- Returns the JSON representation of a tabular data collection.
- format() : self
- formatter() : self
- Set a callback to format each item before json encode.
- indentSize() : self
- DEPRECATION WARNING! This method will be removed in the next major point release.
- removeFlags() : self
- Removes a list of JSON flags.
- save() : int
- Store the generated JSON in the destination filepath.
- useFlags() : bool
- Tells whether the flag is being used by the current JsonConverter.
- useForceObject() : bool
- useHexAmp() : bool
- useHexApos() : bool
- useHexQuot() : bool
- useHexTag() : bool
- useInvalidUtf8Ignore() : bool
- useInvalidUtf8Substitute() : bool
- useNumericCheck() : bool
- usePartialOutputOnError() : bool
- usePreserveZeroFraction() : bool
- usePrettyPrint() : bool
- useThrowOnError() : bool
- useUnescapedLineTerminators() : bool
- useUnescapedSlashes() : bool
- useUnescapedUnicode() : bool
- when() : self
- Apply the callback if the given "condition" is (or resolves to) true.
- withForceObject() : JsonConverter
- withHexAmp() : JsonConverter
- withHexApos() : JsonConverter
- withHexQuot() : JsonConverter
- withHexTag() : JsonConverter
- withInvalidUtf8Ignore() : JsonConverter
- withInvalidUtf8Substitute() : JsonConverter
- withNumericCheck() : JsonConverter
- withoutForceObject() : JsonConverter
- withoutHexAmp() : JsonConverter
- withoutHexApos() : JsonConverter
- withoutHexQuot() : JsonConverter
- withoutHexTag() : JsonConverter
- withoutInvalidUtf8Ignore() : JsonConverter
- withoutInvalidUtf8Substitute() : JsonConverter
- withoutNumericCheck() : JsonConverter
- withoutPartialOutputOnError() : JsonConverter
- withoutPreserveZeroFraction() : JsonConverter
- withoutPrettyPrint() : JsonConverter
- withoutThrowOnError() : JsonConverter
- withoutUnescapedLineTerminators() : JsonConverter
- withoutUnescapedSlashes() : JsonConverter
- withoutUnescapedUnicode() : JsonConverter
- withPartialOutputOnError() : JsonConverter
- withPreserveZeroFraction() : JsonConverter
- withPrettyPrint() : self
- withThrowOnError() : JsonConverter
- withUnescapedLineTerminators() : JsonConverter
- withUnescapedSlashes() : JsonConverter
- withUnescapedUnicode() : JsonConverter
- getList() : callable(): Generator
- methodToFlag() : int
- Returns the PHP json flag associated to its method suffix to ease method lookup.
- prettyPrint() : string
- Pretty Print the JSON string without using JSON_PRETTY_PRINT The method also allow using an arbitrary length for the indentation.
- setFlags() : self
- Sets the encoding flags.
Properties
$chunkSize read-only
public
int<1, max>
$chunkSize
$depth read-only
public
int<1, max>
$depth
$flags read-only
public
int
$flags
$format read-only
public
JsonFormat
$format
$formatter read-only
public
Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64
callable(T, Array): mixed|null
$formatter
$indentSize read-only
public
int<1, max>
$indentSize
$emptyIterable read-only
private
string
$emptyIterable
$end read-only
private
string
$end
$indentation read-only
private
non-empty-string
$indentation
$indentationLevels
private
array<string|int, string>
$indentationLevels
= []
$jsonEncodeChunk read-only
private
callable(array<int, T>): string
$jsonEncodeChunk
$separator read-only
private
string
$separator
$start read-only
private
string
$start
Methods
__call()
public
__call(string $name, array<string|int, mixed> $arguments) : self|bool
Parameters
- $name : string
- $arguments : array<string|int, mixed>
Tags
Return values
self|bool__construct()
public
__construct([int $flags = 0 ][, int<1, max> $depth = 512 ][, int<1, max> $indentSize = 4 ][,
Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64
callable(T, Array): mixed|null $formatter = null ][, int<1, max> $chunkSize = 500 ][, JsonFormat $jsonFormat = JsonFormat::Standard ]) : mixed
Parameters
- $flags : int = 0
- $depth : int<1, max> = 512
- $indentSize : int<1, max> = 4
- $formatter : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 64 callable(T, Array): mixed|null = null
- $chunkSize : int<1, max> = 500
- $jsonFormat : JsonFormat = JsonFormat::Standard
Tags
addFlags()
Adds a list of JSON flags.
public
addFlags(int ...$flags) : self
Parameters
- $flags : int
Return values
selfchunkSize()
Set the indentation size.
public
chunkSize(int<1, max> $chunkSize) : self
Parameters
- $chunkSize : int<1, max>
Return values
selfconvert()
Returns an Iterator that you can iterate to generate the actual JSON string representation.
public
convert(TabularDataProvider|TabularData|iterable<string|int, T> $records[, array<string|int, string> $header = [] ]) : Iterator<string|int, string>
Parameters
- $records : TabularDataProvider|TabularData|iterable<string|int, T>
- $header : array<string|int, string> = []
Tags
Return values
Iterator<string|int, string>create()
DEPRECATION WARNING! This method will be removed in the next major point release.
public
static create() : self
Since version 9.22.0
use League\Csv\JsonConverter::__construct() instead
Tags
Return values
selfdepth()
Set the depth of Json encoding.
public
depth(int<1, max> $depth) : self
Parameters
- $depth : int<1, max>
Return values
selfdownload()
Sends and makes the JSON structure downloadable via HTTP.
public
download(TabularDataProvider|TabularData|iterable<string|int, T> $records[, string|null $filename = null ][, array<string|int, string> $header = [] ]) : int
. Returns the number of characters read from the handle and passed through to the output.
Parameters
- $records : TabularDataProvider|TabularData|iterable<string|int, T>
- $filename : string|null = null
- $header : array<string|int, string> = []
Tags
Return values
intencode()
Returns the JSON representation of a tabular data collection.
public
encode(TabularDataProvider|TabularData|iterable<string|int, T> $records[, array<string|int, string> $header = [] ]) : string
Parameters
- $records : TabularDataProvider|TabularData|iterable<string|int, T>
- $header : array<string|int, string> = []
Tags
Return values
stringformat()
public
format(JsonFormat $format) : self
Parameters
- $format : JsonFormat
Return values
selfformatter()
Set a callback to format each item before json encode.
public
formatter(callable|null $formatter) : self
Parameters
- $formatter : callable|null
Return values
selfindentSize()
DEPRECATION WARNING! This method will be removed in the next major point release.
public
indentSize(int<1, max> $indentSize) : self
Since version 9.19.0
use League\Csv\JsonConverter::withPrettyPrint() instead
Parameters
- $indentSize : int<1, max>
Tags
Return values
selfremoveFlags()
Removes a list of JSON flags.
public
removeFlags(int ...$flags) : self
Parameters
- $flags : int
Return values
selfsave()
Store the generated JSON in the destination filepath.
public
save(TabularDataProvider|TabularData|iterable<string|int, T> $records, SplFileInfo|SplFileObject|Stream|resource|string $destination[, resource|null $context = null ][, array<string|int, string> $header = [] ]) : int
if a Path or a SplFileInfo object is given, the file will be emptying before adding the JSON content to it. For all the other types you are required to provide a file with the correct open mode.
Parameters
- $records : TabularDataProvider|TabularData|iterable<string|int, T>
- $destination : SplFileInfo|SplFileObject|Stream|resource|string
- $context : resource|null = null
- $header : array<string|int, string> = []
Tags
Return values
intuseFlags()
Tells whether the flag is being used by the current JsonConverter.
public
useFlags(int ...$flags) : bool
Parameters
- $flags : int
Return values
booluseForceObject()
public
useForceObject() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseHexAmp()
public
useHexAmp() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseHexApos()
public
useHexApos() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseHexQuot()
public
useHexQuot() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseHexTag()
public
useHexTag() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseInvalidUtf8Ignore()
public
useInvalidUtf8Ignore() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseInvalidUtf8Substitute()
public
useInvalidUtf8Substitute() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseNumericCheck()
public
useNumericCheck() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
boolusePartialOutputOnError()
public
usePartialOutputOnError() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
boolusePreserveZeroFraction()
public
usePreserveZeroFraction() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
boolusePrettyPrint()
public
usePrettyPrint() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseThrowOnError()
public
useThrowOnError() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseUnescapedLineTerminators()
public
useUnescapedLineTerminators() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseUnescapedSlashes()
public
useUnescapedSlashes() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
booluseUnescapedUnicode()
public
useUnescapedUnicode() : bool
tells whether the JSON_HEX_TAG flag is used
Return values
boolwhen()
Apply the callback if the given "condition" is (or resolves to) true.
public
when(callable($this): bool|bool $condition,
Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78
callable($this): Array $onSuccess[,
Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78
callable($this): Array|null $onFail = null ]) : self
Parameters
- $condition : callable($this): bool|bool
- $onSuccess : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array
- $onFail : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable($this): Array|null = null
Return values
selfwithForceObject()
public
withForceObject() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithHexAmp()
public
withHexAmp() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithHexApos()
public
withHexApos() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithHexQuot()
public
withHexQuot() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithHexTag()
public
withHexTag() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithInvalidUtf8Ignore()
public
withInvalidUtf8Ignore() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithInvalidUtf8Substitute()
public
withInvalidUtf8Substitute() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithNumericCheck()
public
withNumericCheck() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithoutForceObject()
public
withoutForceObject() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutHexAmp()
public
withoutHexAmp() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutHexApos()
public
withoutHexApos() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutHexQuot()
public
withoutHexQuot() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutHexTag()
public
withoutHexTag() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutInvalidUtf8Ignore()
public
withoutInvalidUtf8Ignore() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutInvalidUtf8Substitute()
public
withoutInvalidUtf8Substitute() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutNumericCheck()
public
withoutNumericCheck() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutPartialOutputOnError()
public
withoutPartialOutputOnError() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutPreserveZeroFraction()
public
withoutPreserveZeroFraction() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutPrettyPrint()
public
withoutPrettyPrint() : JsonConverter
removes the JSON_PRETTY_PRINT flag
Return values
JsonConverterwithoutThrowOnError()
public
withoutThrowOnError() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutUnescapedLineTerminators()
public
withoutUnescapedLineTerminators() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutUnescapedSlashes()
public
withoutUnescapedSlashes() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithoutUnescapedUnicode()
public
withoutUnescapedUnicode() : JsonConverter
removes the JSON_HEX_TAG flag
Return values
JsonConverterwithPartialOutputOnError()
public
withPartialOutputOnError() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithPreserveZeroFraction()
public
withPreserveZeroFraction() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithPrettyPrint()
public
withPrettyPrint([int<1, max>|null $indentSize = null ]) : self
Parameters
- $indentSize : int<1, max>|null = null
Return values
selfwithThrowOnError()
public
withThrowOnError() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithUnescapedLineTerminators()
public
withUnescapedLineTerminators() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithUnescapedSlashes()
public
withUnescapedSlashes() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConverterwithUnescapedUnicode()
public
withUnescapedUnicode() : JsonConverter
adds the JSON_HEX_TAG flag
Return values
JsonConvertergetList()
private
static getList(Iterator $data, array<string|int, string> $header, JsonFormat $format) : callable(): Generator
Parameters
- $data : Iterator
- $header : array<string|int, string>
- $format : JsonFormat
Tags
Return values
callable(): GeneratormethodToFlag()
Returns the PHP json flag associated to its method suffix to ease method lookup.
private
static methodToFlag(string $method, int $prefixSize) : int
Parameters
- $method : string
- $prefixSize : int
Return values
intprettyPrint()
Pretty Print the JSON string without using JSON_PRETTY_PRINT The method also allow using an arbitrary length for the indentation.
private
prettyPrint(string $json) : string
Parameters
- $json : string
Return values
stringsetFlags()
Sets the encoding flags.
private
setFlags(int $flags) : self
Parameters
- $flags : int