Header

Introduction

Created Monday 18 May 2020

Welcome to Operon! Operon is the state of the art JSON data query, transformation and integration language. Let's dive directly in and write our first query to see how Operon works. Please copy the following query and paste it in your text-editor choice in a file called "query.op".

From
  json:"Hello world"
Select
  $

After running the query, you should get an output "Hello world". Congratulations, you have just run your first Operon-query! For this manual we'll use the notation of "\#>" to denote the output of the query.

Let's start by looking at few examples that should serve as our motivators to thrive learning more Operon.

JSON data queries

From
  json:{
	"fname": "Foo",
	"lname": "Bar",
	"address": [
	  {
		"city": "Footown",
		"street": "Foostreet",
		"postcode": 10100
	  },
	  {
		"city": "Foocity",
		"street": "Foostreet",
		"postcode": 10300
	  }
	]
  }
Select
  $.address[@.city = "Footown"].postcode

#> 10100

JSON data transformations

From
  sequence:[
	{"firstName": "Bin", "lastName": "Bai"},
	{"firstName": "Baa", "lastName": "Baba"},
	{"firstName": "Babba", "lastName": "Ba"}
  ]

Select
  $ Map
	@ + {"fullName": @.firstName + " " + @.lastName}
  End

#> {"firstName": "Bin", "lastName": "Bai", "fullName": "Bin Bai"}
#> {"firstName": "Baa", "lastName": "Baba", "fullName": "Baa Baba"}
#> {"firstName": "Babba", "lastName": "Ba", "fullName": "Babba Ba"}

JSON data integrations

# Generate a random-number every 5 seconds
# and write it into file.
From
  timer:test {
	"initialDelay": 3000,
	"period": 5000
  }

Select
  => random:number()

  -> file:local {
	"path": "/tmp",
	"fileName": "random.dat"
  }

Building microservices

From
  httpserver:test {
	"host": "localhost",
	"port": 8080,
	"paths": [
	  {
		"id": "sayHello",
		"method": "GET",
		"path": "api/v1/hello/:name"
	  }
	]
  }
Select
  When $.id = "sayHello"
	Then {
	  "body": "Hello " + $.params.name + "!"
	}
  Otherwise
	empty
  End

Note: the example above uses "httpserver" component, which must be installed separately.

Ok, now we are ready to take a look into +JSON-dataformat!



Backlinks:
Operon.io:Installation