*/ final class JsonSource implements IteratorAggregate { /** @var iterable */ private iterable $source; /** * @throws InvalidSource */ public function __construct(string $jsonSource) { try { $source = json_decode($jsonSource, associative: true, flags: JSON_THROW_ON_ERROR); } catch (JsonException $e) { throw new InvalidJson($jsonSource, $e); } if (! is_iterable($source)) { throw new SourceNotIterable($jsonSource); } $this->source = $source; } /** * @return Iterator */ public function getIterator(): Traversable { yield from $this->source; } }