diff -r cc60c8dd7924 -r 5bc2bb8b7946 relpipe-data/examples-yaml.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-yaml.xml Mon Feb 21 00:43:11 2022 +0100 @@ -0,0 +1,79 @@ + + + Reading and writing YAML + convert relations to YAML or YAML/JSON to relations + 05200 + + + +

+ YAML is a text format for serializing tree structures into text (like XML). + It can be sometimes tricky, but basic scenarios are intuitive and straightforward. + We can use YAML to describe relational data and load them using the relpipe-in-yaml input filter: +

+ + +

This YAML notation is almost as simple as Recfiles and like Recfiles it can be easily written by hand.

+ +

+ We can also use the JSON notation (it can be read by the same tool – relpipe-in-json is currently just a symlink to relpipe-in-yaml). + JSON is inferior to YAML and XML, but the JSON input filter might be useful when interacting with software that can produce only JSON. + The film relation would look like this in JSON format (shortened): +

+ + +

+ When we want to declare data types + – which is usually a good idea – + we add the attribute-metadata header and move the data under the record node: +

+ +

+ This form (with data types and quotes) is also produced by the relpipe-out-yaml tool. +

+ + +

When we load such YAML, we get this relational data:

+ +

Of course, there might be multiple relations, not only one.

+ + +

+ Once we convert the YAML to relational format, we can run any transformations and conversions as usual. + For example we can use SQL to sort the recordsy by year: +

+ + relpipe-data/examples/film-1.rec]]> + +

and Recfile output filter to get:

+ + +

Or we may use XPath filter:

+ = 1980 and year < 1990']]> +

to get the 80s films:

+ + +

YAML comes into play when we are looking for a friendly format for user-supplied data.

+ +
+ +