Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Etl Adapter Json Laravel Package

flow-php/etl-adapter-json

Laravel-friendly adapter for Flow PHP ETL that reads and writes JSON data, enabling JSON files or streams to be used as ETL sources and destinations. Simple integration with pipelines for transforming and loading structured data.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require flow-php/etl-adapter-json
    

    Ensure your project uses Flow Framework (v10+).

  2. Basic Usage Import the adapter in your ETL pipeline:

    use Flow\ETL\Adapter\JsonAdapter;
    use Flow\ETL\Pipeline;
    
    $pipeline = new Pipeline();
    $pipeline->addAdapter(new JsonAdapter());
    
  3. First Use Case: Parsing JSON Input

    $jsonInput = '{"name": "John", "age": 30}';
    $result = $pipeline->process($jsonInput);
    // Result: Associative array `['name' => 'John', 'age' => 30]`
    
  4. Key Files

    • src/Adapter/JsonAdapter.php (Core logic)
    • tests/ (Unit/integration tests for reference)

Implementation Patterns

Workflow: JSON-to-Array Transformation

$pipeline
    ->addAdapter(new JsonAdapter()) // Parse JSON
    ->addAdapter(new \Flow\ETL\Adapter\FilterAdapter()) // Filter data
    ->addAdapter(new \Flow\ETL\Adapter\ArrayAdapter()); // Output as array

Integration with Flow ETL

  • Chaining Adapters: Use JsonAdapter as the first step in a pipeline to parse raw JSON input.
  • Error Handling: Wrap in a TryCatchAdapter for graceful JSON decode failures:
    $pipeline
        ->addAdapter(new TryCatchAdapter(new JsonAdapter()))
        ->addAdapter(new LogAdapter()); // Log errors
    

Custom JSON Handling

  • Custom Decoding: Extend JsonAdapter to handle non-standard JSON:
    class CustomJsonAdapter extends JsonAdapter {
        protected function decode(string $json): array {
            return json_decode($json, true, 512, JSON_BIGINT_AS_STRING);
        }
    }
    

Batch Processing

  • Streaming Large JSON: Use JsonAdapter with StreamAdapter for large files:
    $pipeline
        ->addAdapter(new StreamAdapter())
        ->addAdapter(new JsonAdapter());
    

Gotchas and Tips

Pitfalls

  1. Malformed JSON

    • JsonAdapter throws \JsonException on invalid JSON. Use TryCatchAdapter or validate input first:
      if (!json_validate($json)) { /* handle error */ }
      
  2. Associative Array Assumption

    • json_decode($json, true) always returns an array, even for objects. Use JsonObjectAdapter (if available) for object preservation.
  3. Memory Limits

    • Large JSON files may hit PHP’s memory_limit. Use JSON_BIGINT_AS_STRING or chunk processing.

Debugging

  • Enable JSON Error Reporting
    JsonAdapter::setThrowExceptions(false); // Default: true
    $pipeline->addAdapter(new LogAdapter()); // Log decode errors
    

Configuration Quirks

  • No Built-in Config: JsonAdapter has no config options. Customize via subclassing or wrapper adapters.
  • Default Options: Uses PHP’s json_decode() defaults (associative arrays, no bigint handling).

Extension Points

  1. Custom Decoders Override decode() to support custom JSON formats (e.g., JSON5, JSON Lines):

    class JsonLinesAdapter extends JsonAdapter {
        protected function decode(string $json): array {
            return array_map('json_decode', explode("\n", $json));
        }
    }
    
  2. Pre/Post-Processing Use BeforeProcessAdapter/AfterProcessAdapter to transform data before/after JSON parsing:

    $pipeline
        ->addAdapter(new BeforeProcessAdapter(function($data) {
            return str_replace('"', "'", $data); // Pre-process
        }))
        ->addAdapter(new JsonAdapter());
    
  3. Performance

    • Cache parsed JSON in AfterProcessAdapter if reprocessing identical inputs:
      $cache = [];
      $pipeline->addAdapter(new AfterProcessAdapter(function($data) use (&$cache) {
          $cache[md5($data)] = $data;
          return $data;
      }));
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style