Skip to main content

Declarative JSON data parsing pipeline

Project description

crispum
=======

Cross-language declarative parsing pipeline.

Installation
------------

| Node: ``npm i crispum --save``
| Python: ``pip install crispum``, or if you're clever
``pipenv install crispum``

Usage
-----

Crispum is designed to take in static JSON schema objects and return
back a parser function which will apply all of the transformations
listed in the schema object.

Here is an example of a simple
`obstruction <https://github.com/bendrucker/obstruction>`__ example.

.. code:: json

{
"type": "simple",
"keys": {
"indeed": "awesome"
}
}

This schema would transform the following object...

.. code:: json

{
"awesome": "it works!"
}

into

.. code:: json

{
"indeed": "it works!"
}

The schema may also be an array of instructions, and can apply
instructions to to the whole object or to each element of an array.

.. code:: json

[{
"type": "pluck",
"key": "indeed"
}, {
"type": "array"
}, {
"type": "conditional",
"key": "foo",
"default": {
"type": "filter"
},
"options": {
"bar": {
"type": "pluck",
"key": "nested"
},
"baz": {
"type": "pluck",
"key": "special"
}
}
}, {
"type": "dearray"
}, {
"type": "simple",
"keys": {
"result": "0",
"extra": "1"
}
}]

This results in a complex multistep schema, which when appled to data
like this...

.. code:: json

{
"extra": "oh hey",
"indeed": [{
"foo": "bar",
"nested": "value"
}, {
"foo": "boozle",
"nested": "lost in space"
}, {
"foo": "baz",
"nested": "value",
"special": "so bazzy"
}]
}

results in...

.. code:: json

{
"result": "value",
"extra": "so bazzy"
}

API
===

``crispum(schema)`` -> ``function (data)``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Create a new crispum parser with the options passed. The returned parse
method takes one parameter, which is input data, and returns the
transformed data.

schema
~~~~~~

| *Required*
| Type: ``object`` or ``array``

The schema may either be a single instruction or an array of them. Each
instruction must have a ``type``, and may optionally contain an
``array`` field.

When ``array`` is true, the current data will be reinterpreted as an
array and each instruction will execute on the entries instead of the
list itself.

Available types are...

array
^^^^^

The array instruction tells the crispum pipeline to run all subsequent
instructions as if they had ``array: true`` set. It also can take in an
optional parameters, ``keys``

``keys`` is a list of keys to copy from the data into each element of
the array before continuing on the pipeline

conditional
^^^^^^^^^^^

The conditional instruction looks at the value of a specified key and
then executes a different instruction based on the value found.

- ``key``: They keyname to check the conditional against
- ``default``: The default instruction if the value found is not in the
options list
- ``options``: An associative array of instruction options

dearray
^^^^^^^

Stops an array pipeline and goes back to interpreting the data as a
whole instead of each element.

filter
^^^^^^

This instruction deletes the current data and does ont take any
parameters. This is useful in combination with ``array`` and
``conditional``

simple
^^^^^^

Simple onyl takes 1 other parameter, which is ``keys``. Keys should be a
valid `obstruction
schema <https://github.com/bendrucker/obstruction#schema-definitions>`__.
The result is the same as the output obstruction would generate, except
extra keys not mentioned in the schema are not removed.

pluck
^^^^^

The pluck instruction takes a given key and rebases the dataset onto it.
It takes in two parameters \* ``key``: The keyname to grab and rebase
the current dataset onto \* ``keys``: An array of extra keys to copy
from the parent object into the plucked value

License
=======

MIT


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

crispum-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

crispum-0.2.0-py2-none-any.whl (7.7 kB view details)

Uploaded Python 2

File details

Details for the file crispum-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for crispum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37669caf71bb28de627d10c7495c3ee87fa8c27e9f7bc42736e5826e21d044d0
MD5 7dc3d8ca09e7cefa74f950a1c4e1ac46
BLAKE2b-256 62adcd321ae4f31ab6624fcebcf9ae74e2c627c6d6a2dea3d708f36f5f54f41d

See more details on using hashes here.

File details

Details for the file crispum-0.2.0-py2-none-any.whl.

File metadata

File hashes

Hashes for crispum-0.2.0-py2-none-any.whl
Algorithm Hash digest
SHA256 291efbfa26470b01e8b940b0f28ba19db48f3dfb9e111a77e3b11d0ce4f15498
MD5 c65ae178cb6bb64e7de7a8e1c67e6763
BLAKE2b-256 01e7b3a99229fbfe2d1a86df2fd965b8b19bb601169f74b9922c147f48fce926

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page