Skip to content

Gasol/php-ext-jq

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Extension for jq

Build Status

This extension allows jq.

Build

% git clone --depth=1 https://github.com/kjdev/php-ext-jq.git
% cd php-ext-jq
% phpize
% ./configure
% make
% make test
% make install

Configuration

jq.ini:

extension=jq.so
; jq.display_errors=Off

Usage

$jq = new Jq;
$jq->load('{"name": "jq", "version": "0.1.0"}');
print_r($jq->filter('.'));
echo 'NAME: ', $jq->filter('.name'), PHP_EOL;
echo 'VERSION: ', $jq->filter('.version'), PHP_EOL;

output:

Array
(
    [name] => jq
    [version] => 0.1.0
)
NAME: jq
VERSION: 0.1.0

Class synopsis

Jq {
  public __construct(void)
  public bool load(string $str)
  public bool loadString(string $str)
  public bool loadFile(string $filename)
  public mixed filter(string $filter, int $flags = 0)
  static public mixed parse(string $str, string $filter, int $flags = 0)
  static public mixed parseString(string $str, string $filter, int $flags = 0)
  static public mixed parseFile(string $filename, string $filter, int $flags = 0)
}

Jq::__construct

public __construct(void)

Create a Jq instance.

Return Values:

Returns a new Jq object


Jq::load

public bool load(string $str)

Load a JSON string.

Parameters:

  • str

    JSON text string.

Return Values:

Returns TRUE on success or FALSE on failure.


Jq::loadString

public bool load(string $str)

Load a JSON string.

alias: Jq::load


Jq::loadFile

public bool loadFile(string $filename)

Load a JSON string from file.

Parameters:

  • filename

    JSON text filen name.

Return Values:

Returns TRUE on success or FALSE on failure.


Jq::filter

public mixed filter(string $filter, int $flags = 0)

Get filtering result of the load string.

Parameters:

  • filter

    jq filter string.

  • flags

    • Jq::RAW is raw output

Return Values:

Returns the result value, or FALSE on error.


Jq::parse

static public mixed parse(string $str, string $filter, int $flags = 0)

Get filtering result of the JSON string.

Parameters:

  • str

    JSON text string.

  • filter

    jq filter string.

  • flags

    • Jq::RAW is raw output

Return Values:

Returns the result value, or FALSE on error.


Jq::parseString

static public mixed parseString(string $str, string $filter, int $flags = 0)

Get filtering result of the JSON string.

alias: Jq::parse


Jq::parseFile

static public mixed parseFile(string $filename, string $filter, int $flags = 0)

Get filtering result of the JSON string file.

Parameters:

  • filename

    JSON text file name.

  • filter

    jq filter string.

  • flags

    • Jq::RAW is raw output

Return Values:

Returns the result value, or FALSE on error.

Examples

  • Setting a Jq::RAW
$jq = new Jq;
$jq->load('{"name": "jq", "version": "0.1.0"}');
print_r($jq->filter('.', JQ::RAW));
echo PHP_EOL;
echo 'NAME: ', $jq->filter('.name', JQ::RAW), PHP_EOL;
echo 'VERSION: ', $jq->filter('.version', JQ::RAW), PHP_EOL;

The above example will output:

{"name":"jq","version":"0.1.0"}
NAME: jq
VERSION: 0.1.0
  • Execute static function
$text = '{"name": "jq", "version": "0.1.0"}';
print_r(Jq::parse($text, '.'));
echo 'NAME: ', Jq::parse($text, '.name'), PHP_EOL;
echo 'VERSION: ', Jq::parse($text, '.version', JQ::RAW), PHP_EOL;

The above example will output:

Array
(
    [name] => jq
    [version] => 0.1.0
)
NAME: jq
VERSION: 0.1.0

About

This extension allows jq

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
COPYING.jq

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 45.9%
  • Shell 33.3%
  • PHP 6.5%
  • Makefile 5.5%
  • Roff 4.7%
  • Yacc 1.5%
  • Other 2.6%