Operon 1-2-3

This article shows the first steps to get started working with Operon.

Get the Operon

Requirement: for this tutorial we use Operon that needs a Linux-operating system to run. You can find a pre-installed playground for Operon from katacoda.com/operon, this is also a good place to start learning Operon by topic. We also have a Windows-version of Operon.

Download Operon (link in the fronpage) and uncompress it (tar -xvf operon.tar.gz. Ensure that the downloaded Operon is executable (chmod +x operon). To use the binary from everywhere we can copy it into /usr/bin -folder. Then we can make a bash-alias for Operon with alias operon='/usr/bin/./operon'. To persist this, the alias-command should be added into .bashrc -file.

Test that Operon starts by issuing command operon (or ./operon if you didn't create the alias). We should get a notifaction to use option --help or give the queryname.

If all works this far, then we can start to test with different queries. To summarize, this is what we can do to get started:

  1. wget https://github.com/operon-io/operon.io-core/releases/download/v0.6.0-SNAPSHOT/operon.tar.gz
  2. tar -xvf operon.tar.gz
  3. chmod +x operon
  4. cp operon /usr/bin
  5. alias operon='/usr/bin/./operon'

NOTE: we use "\" -character to denote the line-break, in the actual command there are no line-breaks.

Query from command-line

The simplest queries can be issued directly from the command-line by giving the "-q" (--query) option:

This should give the result "Hello world!", which is a JSON-string.

Read the input from command-line

In this example we read a Bitcoin -price data from Coindesk's API. We use "curl" -tool to read the API, then we pipe the input to Operon with pipe-character "|". We need to use "-is" (--inputstream) along with "-q" to tell Operon that the input-value is piped from the previous command. These commonly used options can be grouped by just giving option "-iq".

This query accesses the root-value "$" and does the deepscan "..", which finds the field "EUR" from the input-data.

Read the query from the file

Let's create a file "q.op" (the name does not matter), and place a simple query there:

To run this, we invoke command: operon q.op.

  • We define an object which has two keys "fname" and "lname".
  • The key "fname" has value "Foo", and "lname" has value "Bar"
  • The "#" starts a comment.
  • ": $" can be read as "Select root-value", since "$" refers to root-value, which we assigned with "$: {...}"

Accessing objects

Let's access the "fname" of the simple-object that we defined:

This gives us a value "Foo".

Basic filtering

Let's create a bit more complex input-data.

We defined an object, which has key "persons" and this has a value that is an array. The array contains two objects, which both have keys "fname" and "lname".

We want to query the first person from the array. We use the filter "[1]", which takes the first array-item. Note that the indexing starts from 1 in Operon.

The next steps

  • Go through the Learning Operon -presentation
  • Check the tutorials from katacoda.com/operon
  • Check the other articles which show other aspects of Operon, and try to reproduce the examples