Loading

try {
  http:get("/blog/68780805079/zorba-30--kratos")
} catch http:not-found {
  <p>
    404 NOT FOUND.
    Take me home 
  </p>
}
~
~
-- INSERT -- All 6, 17

Zorba 3.0 - Kratos

Posted 1 month ago

We are more than proud to announce the release of Zorba 3.0, codename Kratos. Kratos contains major improvements of the JSONiq language, the language bindings, as well as all of the XQuery and JSONiq modules. Moreover, we made considerable performance improvements and fixed a huge number of bugs. Because we can’t elaborate on all changes, please refer to to the ChangeLog for an exhaustive list of changes.

JSONiq

We have been keeping up with the latest JSONiq language improvements.

Array Selectors and Array Unboxing

JSONiq now features a syntactically much pleasant way to unbox an array or select a member of an array. For example,

[ "foo", "bar" ] [[2]]

extract the second member of the array (“bar”).

Since JSONiq expressions are composable, you can also use any expression for the left-hand side.

{ field : [ "one",  { "foo" : "bar" } ] }.field[[2]].foo

returns “bar”.

Unboxing an array was so far possible using the jn:members function. JSONiq now features a convenient syntax for doing this.

[ "foo", "bar" ][]

returns “foo” and “bar”.

Because all the JSONiq functions and (updating) expressions implement implicit iteration and skip input to which the functionality is not applicable, you can now write something like

([ "foo", "bar" ], { "foo" : "bar" }, true, [ 1, 2, 3 ] )[

which returns

"foo" "bar" 1 2 3

JSound

Over the past decade, the need for more flexible and scalable dataformats such as JSON has greatly increased. The NoSQL universe brings many new ideas on how to build scalable data storage. With JSONiq and Zorba you can easily process all such kinds of data stored in a variety of NoSQL stores. The last missing piece is a way to make sure that the data stored is consistent and sound. This is where schemas come into play. With Zorba 3.0, we are proud to announce the first beta implementation of the JSound schema definition language.

The JSound module provides functions to validate JSONiq objects or arrays (called instances) against a JSound schema. The following example validates a JSON instance object against the line type in an images schema.

import module namespace jsv = "http://jsound.io/modules/validate";

let $jsd := {
   "$namespace" : "http://zorba.io/modules/images/",
   "$types" : [
    {
      "$name" : "line",
      "$kind" : "object",
      "$content" :
      {
        "start" :
        {
          "$type" : "integer"
        },
        "end" :
        {
          "$type" : "integer"
        }
      }
    }
   ]
}

let $instance := {
  "start": 1,
  "end": 5
}
return
  jsv:jsd-valid($jsd, "line", "http://zorba.io/modules/images/", $instance)

The implementation is still beta but we are working on testing and finalizing it with the upcoming release.

Modules & Functions

Beyond the JSONiq changes, we also JSONified several of the modules making them much easier to use.

CSV-to-JSON and Back

A huge amount of data out there is fully structured and available in the CSV format. Mostly, this data comes out of the world’s most famous BI tool (aka Excel) or relational databases. With Zorba’s new CSV-JSON conversion module, it’s very easy to parse CSV data making it available for processing using the powerful JSONiq language.

For example, consider the following query:

import module namespace csv = "http://zorba.io/modules/json-csv";

let $csv := "string,integer,decimal,double,boolean,null
foo,42,98.6,1E4,false,null"
return csv:parse($csv)

which returns

{ "string" : "foo", "integer" : 42, "decimal" : 98.6, "double" : 10000, "boolean" : false, "null" : null }

The parse function provides a huge number of options to customize the conversion (e.g. configuring the separator, turning off casting of unquoted values, or providing custom field names). Of course, the module also allows serialization of JSONiq objects to CSV.

import module namespace csv = "http://zorba.io/modules/json-csv";                                                                                          
 
let $values := (
  {
    "first" : "one",                                                                                                                                                                  
    "second" : "two",
    "third" : "three"
  },
  {   
    "first" : "four",                                                                                                                                                                 
    "second" : "embedded \" quote",
    "third" : "embedded\r\nnewline" 
  }       
)
let $options := { "field-names" : [ "first", "second", "third" ] }                                                                                                                    
return csv:serialize( $values, $options )

HTTP-Client

The HTTP-Client module is a crucial piece for communicating with any kind of service on the Web. So far, the input and output of functions in this module were based on the XML data model (using nodes) making it very hard to use. We have rewritten the module to leverage the JSONiq data model (using objects and arrays) - allowing the developer to interact with the Web much easier. For example, making a complex HTTP request (i.e. including custom headers) and processing the result as XML is as easy as

import module namespace http = "http://zorba.io/modules/http-client";

let $req :=
{
  "method": "POST",
  "href": "http://zorbatest.lambda.nu:8080/http-test-data/request.php",
  "headers": {"foo":"bar"},
  "body": {
    "media-type": "text/plain",
    "content": "
      Dies ist ein kleiner Test
    "
  }
};
return parse-xml(http:send-request($req).body.content)

And Much More

  • All modules take their options as JSONiq objects which greatly improves usability.
  • More and improved optimization rules like hoisting, flwor-merging, or sort elimination.
  • Full encoding support in the file module.
  • Performance improvements of castable as and binary en- and decoding.
  • Even better conformance with the XQuery 3.0 conformance test suite.
  • A new module for fast set-based sequence operations such as value-intersect or value-except.

We can’t wait for you to download Zorba 3.0 and give it a try!