All Projects → sergiorodenas → Stream Parser

sergiorodenas / Stream Parser

Licence: mit
⚡ PHP7 / Laravel Multi-format Streaming Parser

Projects that are alternatives of or similar to Stream Parser

Loaders.gl
Loaders for big data visualization. Website:
Stars: ✭ 272 (-30.43%)
Mutual labels:  json, xml, csv, streaming
Choetl
ETL Framework for .NET / c# (Parser / Writer for CSV, Flat, Xml, JSON, Key-Value, Parquet, Yaml, Avro formatted files)
Stars: ✭ 372 (-4.86%)
Mutual labels:  json, xml, csv, parser
Omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
Stars: ✭ 148 (-62.15%)
Mutual labels:  json, xml, csv, parser
Bancosbrasileiros
Lista de bancos brasileiros | Brazilian banks list
Stars: ✭ 178 (-54.48%)
Mutual labels:  json, xml, csv
Jaxon
Streaming JSON parser for Elixir
Stars: ✭ 145 (-62.92%)
Mutual labels:  json, parser, streaming
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (-61.64%)
Mutual labels:  json, xml, parser
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-78.52%)
Mutual labels:  json, xml, csv
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (-47.83%)
Mutual labels:  json, xml, csv
Validation
validation api extracted from play
Stars: ✭ 194 (-50.38%)
Mutual labels:  json, xml, csv
Csv Parser
A modern C++ library for reading, writing, and analyzing CSV (and similar) files.
Stars: ✭ 359 (-8.18%)
Mutual labels:  json, csv, parser
Tableexport
tableExport(table导出文件,支持json、csv、txt、xml、word、excel、image、pdf)
Stars: ✭ 261 (-33.25%)
Mutual labels:  json, xml, csv
Node Csv
Full featured CSV parser with simple api and tested against large datasets.
Stars: ✭ 3,068 (+684.65%)
Mutual labels:  csv, parser, streaming
Iso 3166 Countries With Regional Codes
ISO 3166-1 country lists merged with their UN Geoscheme regional codes in ready-to-use JSON, XML, CSV data sets
Stars: ✭ 1,372 (+250.9%)
Mutual labels:  json, xml, csv
Uxdm
🔀 UXDM helps developers migrate data from one system or format to another.
Stars: ✭ 159 (-59.34%)
Mutual labels:  json, xml, csv
Filecontextcore
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
Stars: ✭ 91 (-76.73%)
Mutual labels:  json, xml, csv
Unbescape
Advanced yet easy to use escaping library for Java
Stars: ✭ 207 (-47.06%)
Mutual labels:  json, xml, csv
Magento2 Import Export Sample Files
Default Magento 2 CE import / export CSV files & sample files for Firebear Improved Import / Export extension
Stars: ✭ 68 (-82.61%)
Mutual labels:  json, xml, csv
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-79.03%)
Mutual labels:  json, xml, parser
Pxi
🧚 pxi (pixie) is a small, fast, and magical command-line data processor similar to jq, mlr, and awk.
Stars: ✭ 248 (-36.57%)
Mutual labels:  json, csv, parser
Sq
swiss-army knife for data
Stars: ✭ 275 (-29.67%)
Mutual labels:  json, xml, csv

⚡ PHP7 / Laravel Multi-format Streaming Parser

Build Status Latest Version on Packagist Quality Score Code Coverage License

When it comes to parsing XML/CSV/JSON/... documents, there are 2 approaches to consider:

DOM loading: loads all the document, making it easy to navigate and parse, and as such provides maximum flexibility for developers.

Streaming: implies iterating through the document, acts like a cursor and stops at each element in its way, thus avoiding memory overkill.

https://www.linkedin.com/pulse/processing-xml-documents-dom-vs-streaming-marius-ilina/

Thus, when it comes to big files, callbacks will be executed meanwhile file is downloading and will be much more efficient as far as memory is concerned.

Installation

composer require rodenastyle/stream-parser

Recommended usage

Delegate as possible the callback execution so it doesn't blocks the document reading:

(Laravel Queue based example)

use Tightenco\Collect\Support\Collection;

StreamParser::xml("https://example.com/users.xml")->each(function(Collection $user){
    dispatch(new App\Jobs\SendEmail($user));
});

Practical Input/Code/Output demos

XML

<bookstore>
    <book ISBN="10-000000-001">
        <title>The Iliad and The Odyssey</title>
        <price>12.95</price>
        <comments>
            <userComment rating="4">
                Best translation I've read.
            </userComment>
            <userComment rating="2">
                I like other versions better.
            </userComment>
        </comments>
    </book>
    [...]
</bookstore>
use Tightenco\Collect\Support\Collection;

StreamParser::xml("https://example.com/books.xml")->each(function(Collection $book){
    var_dump($book);
    var_dump($book->get('comments')->toArray());
});
class Tightenco\Collect\Support\Collection#19 (1) {
  protected $items =>
  array(4) {
    'ISBN' =>
    string(13) "10-000000-001"
    'title' =>
    string(25) "The Iliad and The Odyssey"
    'price' =>
    string(5) "12.95"
    'comments' =>
    class Tightenco\Collect\Support\Collection#17 (1) {
      protected $items =>
      array(2) {
        ...
      }
    }
  }
}
array(2) {
  [0] =>
  array(2) {
    'rating' =>
    string(1) "4"
    'userComment' =>
    string(27) "Best translation I've read."
  }
  [1] =>
  array(2) {
    'rating' =>
    string(1) "2"
    'userComment' =>
    string(29) "I like other versions better."
  }
}

Additionally, you could make use of ->withSeparatedParametersList() to get the params of each element separated on the __params property. Also, ->withoutSkippingFirstElement() could be of help to parse the very first item (usually the element that contains the elements).

JSON

[
  {
    "title": "The Iliad and The Odyssey",
    "price": 12.95,
    "comments": [
      {"comment": "Best translation I've read."},
      {"comment": "I like other versions better."}
    ]
  },
  {
    "title": "Anthology of World Literature",
    "price": 24.95,
    "comments": [
      {"comment": "Needs more modern literature."},
      {"comment": "Excellent overview of world literature."}
    ]
  }
]
use Tightenco\Collect\Support\Collection;

StreamParser::json("https://example.com/books.json")->each(function(Collection $book){
    var_dump($book->get('comments')->count());
});
int(2)
int(2)

CSV

title,price,comments
The Iliad and The Odyssey,12.95,"Best translation I've read.,I like other versions better."
Anthology of World Literature,24.95,"Needs more modern literature.,Excellent overview of world literature."
use Tightenco\Collect\Support\Collection;

StreamParser::csv("https://example.com/books.csv")->each(function(Collection $book){
    var_dump($book->get('comments')->last());
});
string(29) "I like other versions better."
string(39) "Excellent overview of world literature."

License

This library is released under MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].