Socket
Socket
Sign inDemoInstall

jsonata

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonata - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

187

functions.md
## JSONata Function Library
The following is a proposed function library for use within JSONata expressions.
This is work in progress. Some of these functions have been implemented, but mostly not.
This is work in progress. Some of these functions have been implemented, and those that have not are marked accordingly.
#### String functions
- `$string(arg)`
### String functions
#### `$string(arg)`
Casts the `arg` parameter to a string using the following casting rules
Casts the `arg` parameter to a string using the following casting rules
- Strings are unchanged

@@ -15,7 +15,7 @@ - Functions are converted to an empty string

- `$length(str)`
####`$length(str)`
Returns the number of characters in the string `str`
Returns the number of characters in the string `str`. An error is thrown if `str` is not a string.
- `$substring(str, start[, length])`
####`$substring(str, start[, length])`

@@ -28,37 +28,56 @@ Returns a string containing the characters in the first parameter `str`

- `$substringBefore(str, chars)`
####`$substringBefore(str, chars)`
Returns the substring before the first occurrence of the character sequence `chars` in `str`.
If `str` does not contain `chars`, then it returns `str`.
Returns the substring before the first occurrence of the character sequence `chars` in `str`.
If `str` does not contain `chars`, then it returns `str`.
####`$substringAfter(str, chars)`
- `$substringAfter(str, chars)`
Returns the substring after the first occurrence of the character sequence `chars` in `str`.
If `str` does not contain `chars`, then it returns `str`.
Returns the substring after the first occurrence of the character sequence `chars` in `str`.
If `str` does not contain `chars`, then it returns `str`.
#### `$uppercase(str)`
- `$uppercase(str)`
Returns a string with all the characters of `str` converted to uppercase.
Returns a string with all the characters of `str` converted to uppercase.
#### `$lowercase(str)`
- `$lowercase(str)`
Returns a string with all the characters of `str` converted to lowercase.
Returns a string with all the characters of `str` converted to lowercase.
#### `$split(str, separator, limit)`
- `$split(str, separator)`
Splits the `str` parameter into an array of substrings. It is an error if `str` is not a string.
- `$join(array[, separator])`
The optional `separator` parameter
specifies the characters within the `str` about which it should be split. If `separator` is
not specified, then the empty string is assumed, and `str` will be split into an array of single
characters. It is an error if `separator` is not a string.
- `$format(pattern, ...)`
The optional `limit` parameter is a number that specifies the maximum number of substrings to
include in the resultant array. Any additional substrings are discarded. If `limit` is not
specified, then `str` is fully split with no limit to the size of the resultant array.
It is an error if `limit` is not a non-negative number.
#### `$join(array[, separator])`
Joins an array of component strings into a single concatenated string with each component string
separated by the optional `separator` parameter.
It is an error if the input array contains an item which isn't a string.
If `separator` is not specified, then it is assumed to be the empty string, i.e. no separator
between the component strings. It is an error if `separator` is not a string.
#### `$format(pattern, ...)` - to be implemented
[printf style formatting](https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification). Other formatting schemes are available.
#### Numerical functions
### Numerical functions
- `$number(arg)`
#### `$number(arg)`
Casts the `arg` parameter to a number using the following casting rules
Casts the `arg` parameter to a number using the following casting rules
- Numbers are unchanged

@@ -68,81 +87,107 @@ - Strings that contain a sequence of characters that represent a legal JSON number are converted to that number

- `$sum(array)`
- `$abs(number)`
- `$max(array)`
- `$min(array)`
- `$round(number)`
#### `$abs(number)` - to be implemented
#### `$round(number)` - to be implemented
Rounds up to the nearest integer
Rounds up to the nearest integer
- `$roundHalfToEven(number)`
#### `$roundHalfToEven(number)` - to be implemented
[Round half to even](https://en.wikipedia.org/wiki/Rounding#Round_half_to_even) Commonly used in financial calculations.
- `$average(array)`
- `$power(base, exponent)`
#### `$power(base, exponent)` - to be implemented
#### Boolean functions
### Numeric aggregation functions
- `$boolean(arg)`
#### `$sum(array)`
Casts the argument to a Boolean using the following rules:
Returns the arithmetic sum of an array of numbers.
It is an error if the input array contains an item which isn't a number.
#### `$max(array)`
Returns the maximum number in an array of numbers.
It is an error if the input array contains an item which isn't a number.
#### `$min(array)`
Returns the minimum number in an array of numbers.
It is an error if the input array contains an item which isn't a number.
#### `$average(array)`
Returns the mean value of an array of numbers.
It is an error if the input array contains an item which isn't a number.
### Boolean functions
#### `$boolean(arg)`
Casts the argument to a Boolean using the following rules:
| Argument type|Result|
| -------------|------|
| Boolean| unchanged|
| string: empty| `false`|
| string: non-empty| `true`|
| number: 0 | `false`|
| number: non-zero | `true`|
| null | `false`|
| array: empty| `false`|
| array: contains a member that casts to `true`| `true`|
| array: all members cast to `false`| `false`|
| object: empty | `false`|
| object: non-empty | `true`|
| function | `false`|
| Argument type | Result |
| ------------- | ------ |
| Boolean | unchanged |
| string: empty | `false`|
| string: non-empty | `true` |
| number: 0 | `false`|
| number: non-zero | `true` |
| null | `false`|
| array: empty | `false` |
| array: contains a member that casts to `true` | `true` |
| array: all members cast to `false` | `false` |
| object: empty | `false` |
| object: non-empty | `true` |
| function | `false` |
- `$not(arg)`
#### `$not(arg)`
Returns Boolean NOT on the argument. `arg` is first cast to a boolean
Returns Boolean NOT on the argument. `arg` is first cast to a boolean
#### `$exists(arg)`
#### Date/Time functions
Returns Boolean `true` if the arg expression evaluates to a value, or
`false` if the expression does not match anything (e.g. a path to a non-existent
field reference).
#### Array functions
### Date/Time functions
tbd
- `$count(array)`
### Array functions
Returns the number of items in the array
#### `$count(array)`
Returns the number of items in the array
- `$append(array, array)`
#### `$append(array, array)`
Appends two arrays
Appends two arrays
- `$flatten(array)`
#### `$flatten(array)` - to be implemented
Flattens nested array into flat array
Flattens nested array into flat array
- `$range(start, end, increment)`
#### `$range(start, end, increment)` - to be implemented
Generates an array of numbers starting with `start`, not exceeding `end`, in increments of `increment` (defaults to 1)
Generates an array of numbers starting with `start`, not exceeding `end`, in increments of `increment` (defaults to 1)
#### Object functions
### Object functions
- `$keys(object)`
#### `$keys(object)`
Returns an array containing the keys in the object
Returns an array containing the keys in the object
- `$lookup(object, key)`
#### `$lookup(object, key)`
Returns the value assosciated with `key` in `object`
Returns the value assosciated with `key` in `object`
- `$merge(object, object)`
#### `$merge(object, object)` - to be implemented
Returns an object containing the union of the two `object` parameters. If an entry in the second object
has the same key as an entry in the first, then the value will be overridden by the second.
Returns an object containing the union of the two `object` parameters. If an entry in the second object
has the same key as an entry in the first, then the value will be overridden by the second.
#### Higher-order functions
### Higher-order functions
- `$map`
#### `$map`
#### `$reduce`
{
"name": "jsonata",
"version": "1.0.5",
"version": "1.0.6",
"description": "JSON query and transformation language",

@@ -5,0 +5,0 @@ "main": "jsonata.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc