mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
129 lines
3.6 KiB
YAML
129 lines
3.6 KiB
YAML
# Copyright 2020-2021 Lowdefy, Inc
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
_ref:
|
|
path: templates/operators.yaml.njk
|
|
transformer: templates/operatorsMethodTransformer.js
|
|
vars:
|
|
pageId: _json
|
|
pageTitle: _json
|
|
filePath: operators/_json.yaml
|
|
description: |
|
|
The `_json` parses and writes JSON strings.
|
|
methods:
|
|
- name: parse
|
|
types: |
|
|
```
|
|
(value: string): any
|
|
```
|
|
description: |
|
|
The `_json.parse` method parses a JSON string into an object.
|
|
arguments: |
|
|
###### string
|
|
The string to parse.
|
|
examples: |
|
|
###### Parse a JSON string:
|
|
```yaml
|
|
_json.parse: '{"key": "Value", "boolean": true, "array": [1, 2]}'
|
|
```
|
|
Returns:
|
|
```
|
|
key: Value
|
|
boolean: true
|
|
array:
|
|
- 1
|
|
- 2
|
|
```
|
|
- name: stringify
|
|
types: |
|
|
```
|
|
({on: any, options?: object}): string
|
|
([on: any, options?: object]): string
|
|
```
|
|
description: |
|
|
The `_json.stringify` method creates a JSON string from an object.
|
|
arguments: |
|
|
###### object
|
|
- `on: any`: The object to stringify.
|
|
- `options: object`: Optional settings.
|
|
- `stable: boolean`: If set to true, equal objects will be stringified to the same string. Object keys are sorted.
|
|
- `space: number | string`: Used to insert whitespace to increase legibility. If a number, it is the number of space character to use. If a string, the string is used as whitespace. The default is `2`.
|
|
|
|
examples: |
|
|
###### Stringify an object as JSON:
|
|
```yaml
|
|
_json.stringify:
|
|
on:
|
|
key: Value
|
|
boolean: true
|
|
array:
|
|
- 1
|
|
- 2
|
|
```
|
|
```yaml
|
|
_json.stringify:
|
|
- key: Value
|
|
boolean: true
|
|
array:
|
|
- 1
|
|
- 2
|
|
```
|
|
Returns (as a string):
|
|
```text
|
|
'{
|
|
"key": "Value",
|
|
"boolean": true,
|
|
"array": [
|
|
1,
|
|
2
|
|
]
|
|
}'
|
|
```
|
|
###### Stable option:
|
|
```yaml
|
|
_json.stringify:
|
|
on:
|
|
key: Value
|
|
boolean: true
|
|
array:
|
|
- 1
|
|
- 2
|
|
options:
|
|
stable: true
|
|
```
|
|
Returns (as a string):
|
|
```text
|
|
'{
|
|
"array": [
|
|
1,
|
|
2
|
|
],
|
|
"boolean": true,
|
|
"key": "Value"
|
|
}''
|
|
```
|
|
###### Space option:
|
|
```yaml
|
|
_json.stringify:
|
|
on:
|
|
key: Value
|
|
boolean: true
|
|
array:
|
|
- 1
|
|
- 2
|
|
options:
|
|
space: 0
|
|
```
|
|
Returns `'{"key":"Value","boolean":true,"array":[1,2]}'`
|