halaxa / json-machine

Efficient, easy-to-use, and fast PHP JSON stream parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Basic Usage Using PHP and Brew

JamesAllgood opened this issue · comments

commented

Hey!

This is going to be a really basic question, I downloaded the library last week using brew. But having some issues getting it working, never used composer before and when its trying to use the import file command its not working?

I've used the example but it falls over on trying to use the items::from file command.

The code looks like this but unsure how to fix it?

use JsonMachine\Items;
use JsonMachine\JsonDecoder\PassThruDecoder;

$users = Items::fromFile

Your snippet doesn't seem complete. Also, usage with PassThruDecoder is described in Readme. Did you check it out?

commented

Here’s the code and the layout of the web repository, the index file is what hosts the code pasted below.

<?php

//https://github.com/halaxa/json-machine

require __DIR__ . '/vendor/autoload.php';

// $loader = require __DIR__ . '/vendor/autoload.php';
// print_r($loader);

$fruits = Items::fromFile('fruitsArray.json', ['pointer' => '/results/-/color']);

foreach ($fruits as $key => $value) {
    // 1st iteration:
    $key == 'color';
    $value == 'red';
    $fruits->getMatchedJsonPointer() == '/results/-/color';
    $fruits->getCurrentJsonPointer() == '/results/0/color';

    // 2nd iteration:
    $key == 'color';
    $value == 'yellow';
    $fruits->getMatchedJsonPointer() == '/results/-/color';
    $fruits->getCurrentJsonPointer() == '/results/1/color';
}
commented

67204C38-3B2F-461A-BC44-A052945EB843

What error specifically do you get? Can you also provide the contents of fruitsArray.json?

Please provide the requested info in order to keep this issue open.

commented

What error specifically do you get? Can you also provide the contents of fruitsArray.json?

This is the location of the code.

http://test.themeparkguide.co.uk
http://test.themeparkguide.co.uk/fruitsArray.json

index.php code is...

Screenshot 2023-06-02 at 20 37 00