Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/concepts/SLON.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: default
title: SLON format
parent: Concepts
nav_order: 99
---

# SLON format

[SLON](https://github.com/nmaguiar/slon) (Single Line Object Notation) is a lightweight data serialization format designed to
compress JSON-like structures into a concise, human-readable syntax. It keeps the familiar concepts of maps and arrays while
trimming unnecessary characters, making it easier to scan large payloads in logs or share configuration snippets inline.

## Why SLON?

* **Compact syntax** – Braces and commas are optional when the structure is unambiguous, allowing records to fit on a single
line without sacrificing readability.
* **JSON-compatible** – Every SLON document can be converted to JSON and vice versa, enabling quick interchange between
OpenAF helpers that expect JSON and those that accept SLON.
* **Human-friendly defaults** – Strings can be quoted only when needed, and key-value pairs rely on `:` separators, so editing
data by hand is straightforward.

## Working with SLON in OpenAF

OpenAF includes multiple helpers to convert data back and forth between JSON and SLON:

* `AF.toSLON()` / `AF.toCSLON()` – render maps or arrays to SLON (optionally with ANSI colors for terminals).
* `AF.fromSLON()` / `AF.fromJSSLON()` – parse SLON strings back into OpenAF objects.
* `$toSLON`, `$cslon`, `$oafp` – templating helpers that emit or parse SLON documents inline.

Because SLON is interchangeable with JSON, documentation frequently mentions parameters that accept "JSON/SLON" values. You can
freely decide which notation is more convenient for you, and OpenAF will transparently parse the data.

For complete syntax details and reference implementations, visit the [SLON GitHub repository](https://github.com/nmaguiar/slon).
3 changes: 2 additions & 1 deletion docs/concepts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Main concepts
* __[$from](OpenAF-nLinq.md)__
* __[oJob.io](oJobIO.md)__
* __[oafp](oafp.md)__
* __[SLON format](SLON.md)__
* __[Shebang](shebang.md)__
* __[Java Support](java.md)__
* __[$path](OpenAF-path.md)__
* __[Static installation](static-installation.md)__
* __[Container images](container-images.md)__
* __[Container images](container-images.md)__
8 changes: 4 additions & 4 deletions docs/concepts/llm.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ OpenAF provides first-class support for Local Language Model (LLM) prompts via t

### OAF_MODEL

Used by the `$llm` function and OpenAF JavaScript APIs to select and configure a GPT model. If no explicit model is passed to `$llm()`, OpenAF will look at `OAF_MODEL` as a JSON or SLON string.
Used by the `$llm` function and OpenAF JavaScript APIs to select and configure a GPT model. If no explicit model is passed to `$llm()`, OpenAF will look at `OAF_MODEL` as a JSON or [SLON](https://github.com/nmaguiar/slon) string.

- Type: string (JSON/SLON) or simple `<type>` name
- Type: string (JSON/[SLON](https://github.com/nmaguiar/slon)) or simple `<type>` name
- Default key: `OAF_MODEL`

Examples:

```bash
# Full JSON configuration (SLON is also supported)
# Full JSON configuration ([SLON](https://github.com/nmaguiar/slon) is also supported)
export OAF_MODEL='{ \
type: "openai", \
key: "YOUR_OPENAI_API_KEY",
Expand Down Expand Up @@ -76,7 +76,7 @@ TOPIC=love && printf "Write a poem about ${TOPIC}" | oafp in=llm
## Tips

- **Environment isolation**: Set these variables in your CI/CD or container environment to avoid hard-coding secrets.
- **SLON support**: OpenAF will parse SLON (Single Line Object Notation) if you prefer a more compact syntax.
- **[SLON](https://github.com/nmaguiar/slon) support**: OpenAF will parse [SLON](https://github.com/nmaguiar/slon) (Single Line Object Notation) if you prefer a more compact syntax.
- **Multiple providers**: You can switch providers by changing `type` (e.g. `openai`, `gemini`, `ollama`, `anthropic`).

## Reference Table: OAF_MODEL / OAFP_MODEL Fields
Expand Down
8 changes: 4 additions & 4 deletions docs/guides/oafp/oafp-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Using the same unix “pipe” mechanism it’s possible to apply different cate
| avg(arrayNumber) | base | The average value of an array of numeric fields | avg([].y) |
| at(idx) | 20241205 | Returns the array index entry | [].at(5) |
| ceil(number) | base | Returns the smallest integer that is equal or less than a specific numeric field value | [].ceil(y) |
| ch(name, op, arg1, args2) | 20240801 | Wrapper for OpenAF's channel functions over a 'name' channel, an 'op' operation between get, set, unset, size, getAll, getKeys, unsetAll; depending on the 'op', 'arg1' and 'arg2' can be provided with values as objects or JSON/SLON | ch('a', 'set', 'a', 'abc').ch('a', 'get', 'a', __) |
| ch(name, op, arg1, args2) | 20240801 | Wrapper for OpenAF's channel functions over a 'name' channel, an 'op' operation between get, set, unset, size, getAll, getKeys, unsetAll; depending on the 'op', 'arg1' and 'arg2' can be provided with values as objects or JSON/[SLON](https://github.com/nmaguiar/slon) | ch('a', 'set', 'a', 'abc').ch('a', 'get', 'a', __) |
| concat(x, y) | 20240209 | Concats arrays or strings | concat('abc', '123') |
| contains(string/array, any) | base | Returns true of false if a string field contains a specific value | files[?contains(filename, 'openaf.jar') == `true` |
| count_by(arr, 'field') | all | Returns a count by array with the '_count' per value of the provided 'field' | count_by([], 'isFile') |
Expand All @@ -92,7 +92,7 @@ Using the same unix “pipe” mechanism it’s possible to apply different cate
| from_csv(str, options) | 20240801 | Given a string CSV representation tries to parse to an array | from_csv(@, '(withDelimiter:\"|\",withHeader:false)') |
| from_datef(date, 'format') | 20240228 | Converts a date type into a string given a 'format' (equivalent to OpenAF's ow.format.fromDate) | from_datef(to_datef('20240202', 'yyyyMMdd'), 'yyyy') |
| from_json(str) | 20240215 | Converts a json string representation into an object | from_json('{a:123}')" |
| from_ms(x, 'format') | 20240209 | Shortcut for OpenAF's ow.format.elapsedTime4ms function. The format is represented as a SLON/JSON string | from_ms(`12000`,'(abrev:true)') |
| from_ms(x, 'format') | 20240209 | Shortcut for OpenAF's ow.format.elapsedTime4ms function. The format is represented as a [SLON](https://github.com/nmaguiar/slon)/JSON string | from_ms(`12000`,'(abrev:true)') |
| from_numSpace(str, sep) | 20241207 | Tries to convert a string number with thousands separators back to a number | from_numSpace('123 456', ' ') |
| from_siAbbr(x) | 20240209 | Given a string with SI numeric abbreviation will convert it to the absolute value | from_siAbbr('100m') |
| from_slon(obj) | 20240215 | Converts a slon string representation into an object | from_slon('(abc: 123)') |
Expand Down Expand Up @@ -127,7 +127,7 @@ Using the same unix “pipe” mechanism it’s possible to apply different cate
| not_null(any) | base | Returns the non-null value between the provided fields | [].not_null(a,b) |
| now(diff) | 20240302 | Returns the current unix timestamp number with a negative diff (or positive for dates in the future) |
| nvl(field, value) | 20240216 | Returns the provided value in case a field value is undefined or null | nvl(nullField, 'n/a') |
| oafp(str) | 20240812 | Executes an oafp (inception) with the provided map in JSON or SLON string format | oafp('(file:data.json)') |
| oafp(str) | 20240812 | Executes an oafp (inception) with the provided map in JSON or [SLON](https://github.com/nmaguiar/slon) string format | oafp('(file:data.json)') |
| ojob(file, jsslon) | 20241116 | Executes a 'file' oJob, with 'jsslon' as args, returning the output (if ow.ojob.output is used) | ojob('ojob.io/echo', obj) |
| opath(str) | 20240801 | Inception function to go over other path filters in 'str' applied over the original object before current transformations | files[].{ name: filename, path: opath('originalPath') } |
| path(obj, str) | 20240801 | Inception function to have other path filters in 'str' applied over 'obj' | path(@, 'filename') |
Expand Down Expand Up @@ -176,7 +176,7 @@ Using the same unix “pipe” mechanism it’s possible to apply different cate
| to_numAbbr(num) | 20240209 | Given an absolute number will return a string with SI abbreviation | to_numAbbr(`12345678`) |
| to_number(any) | base | Transforms any input into a number | to_number(`123`) |
| to_numSpace(num, space) | 20241207 | Transforms a number input to a string with thousands separator 'space' | to_numSpace(123456, ',') |
| to_slon(obj) | 20240215 | Given an object will return the SLON representation of it. | to_slon(@) |
| to_slon(obj) | 20240215 | Given an object will return the [SLON](https://github.com/nmaguiar/slon) representation of it. | to_slon(@) |
| to_string(any) | base | Transforms any input into a string | to_string(`123`) |
| to_toml(obj) | 20240502 | Given an object outputs a TOML format string if possible | to_toml(@) |
| trim(str) | 20240209 | Given a string will return a trimmed version of it | trim(@) |
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/oafp/oafp-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here are some of the available helpers:
| $ft | uses the $ft format function |
| $path | uses the $path function to query objects |
| $from | uses the $from & fromNLinq to query objects |
| $oafp | uses the oafp function (inception) to parse the provided JSON/SLON string and return the results (tip: use with the #with helper) |
| $oafp | uses the oafp function (inception) to parse the provided JSON/[SLON](https://github.com/nmaguiar/slon) string and return the results (tip: use with the #with helper) |
| $toSLON | shows the ow.format.toSLON version of an object |
| $get | shows the corresponding value for a key on $get |
| $getObj | equivalent to $get with the extra parameter for $$.get path |
Expand All @@ -43,7 +43,7 @@ Here are some of the available helpers:
| $pchart | shows an ansi ascii line chart with an object and a format string: "unit path:color:legend... [-min:0] [-max:100] [-hsize:40] [-vsize:10]" |
| $output | shows an $output representation of an object (aObj as 1st arg and options in slon as 2nd arg) |
| $cjson | shows an ansi ascii colority representation fo an object |
| $cslon | shows an ansi ascii colored SLON representation of an object |
| $cslon | shows an ansi ascii colored [SLON](https://github.com/nmaguiar/slon) representation of an object |
| $pmap | shows an ansi ascii printMap representation of an object |
| $jsmap | shows a HTML representation of an object |
| $t | given a template and an object instance, as arguments, will process and return the template |
Expand Down
Loading
Loading