Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use json instead of json_object #73

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 9 additions & 9 deletions content/filterx/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ filterx {
The same is true for complex objects, like JSON, for example:

```shell
js = json_object({
js = json({
"key": "value",
"second-key": "another-value"
});
Expand Down Expand Up @@ -145,7 +145,7 @@ Variables can have the following types. All of these types have a matching funct
- `dict`
- `double`
- `int`
- [`json, json_object`]({{< relref "/filterx/function-reference.md#json" >}}) and [`json_array`]({{< relref "/filterx/function-reference.md#json-array" >}}) for JSON or JSON-like objects. The `json` type is an alias for the `json_object` type.
- [`json`]({{< relref "/filterx/function-reference.md#json" >}}) and [`json_array`]({{< relref "/filterx/function-reference.md#json-array" >}}) for JSON or JSON-like objects.
- `list`
- `null`
- `otel_array`
Expand Down Expand Up @@ -254,7 +254,7 @@ my_list = []; # Creates an empty list (which defaults to a JSON list)
my_array = {}; # Creates an empty dictionary (which defaults to a JSON object)

my_list2 = json_array(); # Creates an empty JSON list
my_array2 = json_object(); # Creates an empty JSON object. json() is an alias for json_object()
my_array2 = json(); # Creates an empty JSON object.
```

You can add elements to lists and dictionaries like this:
Expand Down Expand Up @@ -287,7 +287,7 @@ ${MESSAGE} = list;

In all three cases, the value of `${MESSAGE}` is the same JSON array: `["first_element", "second_element", "third_element"]`.

You can define JSON objects using the `json_object` type, for example:
You can define JSON objects using the `json` type, for example:

```shell
js1 = json();
Expand All @@ -300,14 +300,14 @@ js1 += {
}
};

js2 = json_object({"key": "value"})
js2 = json({"key": "value"})
```

Naturally, you can assign values from other variables to an object, for example:

```shell
js = json_array(["foo", "bar", "baz"]);
${MESSAGE} = json_object({
${MESSAGE} = json({
"key": "value",
"list": list
});
Expand All @@ -316,7 +316,7 @@ ${MESSAGE} = json_object({
or

```shell
js = json_object({
js = json({
"key": ${MY-NAME-VALUE-PAIR},
"key-from-expression": isset(${HOST}) ? ${HOST} : "default-hostname",
"list": list
Expand Down Expand Up @@ -471,10 +471,10 @@ If you're modifying messages using FilterX (for example, you extract a value fro
- Local and pipeline variables are not included in the message, you must assign their value to a macro or name-value pair that's included in the destination template to send them to the destination.
- When sending data to `opentelemetry()` destinations, if you're modifying messages received via the `opentelemetry()` source, then you must explicitly update the original (raw) data structures in your FilterX block, otherwise the changes won't be included in the outgoing message. For details, see {{% xref "/filterx/filterx-otel/_index.md#modify-otel" %}}.

<!--
<!--
- underscores vs hyphens in filterx? everywhere else we use mainly hyphens (parse_kv vs parse-kv) > only underscores work for now
- make flags (like ignorecase) of regexp_subst available for regexp_search
- Aliases for options that are the same but have different names in filterx reimplementations?
- Aliases for options that are the same but have different names in filterx reimplementations?
- csv-parser: delimiters vs parse_csv: delimiter
- inconsistency in parse_csv: string_delimiters vs delimiter

Expand Down
9 changes: 5 additions & 4 deletions content/filterx/function-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,17 @@ Usage: `istype(object, "type_str")`
For example:

```shell
istype({"key": "value"}, "json_object"); # True
obj = json();
istype(obj, "json_object"); # True
istype(${PID}, "string");
istype(my-local-json-object.mylist, "json_array");
```

If the object doesn't exist, `istype()` returns with an error, causing the FilterX statement to become false, and logs an error message to the `internal()` source of {{< product >}}.

## json, json_object {#json}
## json {#json}

Cast a value into a JSON object. `json_object()` is an alias for `json()`.
Cast a value into a JSON object.

Usage: `json(<string or expression to cast as json>)`

Expand Down Expand Up @@ -362,7 +363,7 @@ Deletes ([unsets](#unset)) the empty fields of an object, for example, a JSON ob

Usage: `unset_empties(object, recursive=true)`

<!-- FIXME add a before/after example, for recursive and non-recursive cases
<!-- FIXME add a before/after example, for recursive and non-recursive cases

dict = json({"foo": "", "bar": "-", "baz": "N/A", "almafa": null, "kortefa": {"a":{"s":{"d":{}}}}, "szilvafa": [[[]]]});
defaults_dict = dict;
Expand Down
Loading