Skip to content

Commit

Permalink
Add documentation of provided global functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonAndre committed Sep 28, 2022
1 parent c642006 commit 212bf54
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,48 @@ var_dump($res) //int(5)

```

## simdjson_php API

```php
<?php
/**
* Similar to json_decode()
*
* @returns array|stdClass|string|float|int|bool|null
* @throws RuntimeException for invalid JSON (or document over 4GB, or out of range integer/float)
*/
function simdjson_decode(string $json, bool $assoc = false, int $depth = 512) {}

/**
* Returns true if json is valid.
*
* @returns ?bool (null if depth is invalid)
*/
function simdjson_is_valid(string $json, int $depth = 512) : ?bool {}

/**
* Parses $json and returns the number of keys in $json matching the JSON pointer $key
*
* @returns ?bool (null if depth is invalid)
*/
function simdjson_key_count(string $json, string $key, int $depth = 512) : ?int {}

/**
* Returns true if the JSON pointer $key could be found.
*
* @returns ?bool (null if depth is invalid, false if json is invalid or key is not found)
*/
function simdjson_key_exists(string $json, string $key, int $depth = 512) : ?bool {}

/**
* Returns the value at $key
*
* @returns array|stdClass|string|float|int|bool|null the value at $key
* @throws RuntimeException for invalid JSON (or document over 4GB, or out of range integer/float)
*/
function simdjson_key_value(string $json, string $key, bool $assoc = unknown, int $depth = unknown) {}
```

## Edge cases

There are some differences from `json_decode()` due to the implementation of the underlying simdjson library. This will throw a RuntimeException if simdjson rejects the JSON.
Expand Down

0 comments on commit 212bf54

Please sign in to comment.