$processor$: get-data

get-data processor is used to get data from a JSON files in the package or from document-metadata in sitemap.
-- string foo:
$processor$: get-data
Lang:
ftd
Assuming foo: "hello" is part of “data”, the variable foo will be get “hello” as the value.

Key

By default, the name of the variable or list where the data is being store is used as the key. You can overwrite the key using key attribute:
-- string foo:
$processor$: get-data
key: some-other-key-instead-of-foo
Lang:
ftd

Default Value

If the data is not found, we use the body as default value if body is available.
-- string foo:
$processor$: get-data

"hello world"
Lang:
ftd
The body must be valid json, compatible with the data type on which we are using the get-data processor.

Default Value in Caption For Basic Types

For basic types like integer, boolean etc, the default value can also be provided in the caption. E.g.
-- string foo: hello world
$processor$: get-data
Lang:
ftd
Providing both body and caption when using get-data is an error.

Reading data from JSON File

We will be reading the data from JSON file and injecting the value to the caller of the processor (caller could be variable or component).

Step - 1 : We need to make two files i.e. one file should be .ftd and another file should be .json

Step - 2 : Creating .ftd (for example, record.ftd)
-- record person:
caption name:
integer age:
string gender:

-- person arpita:
$processor$: get-data
file: foo.json

-- ftd.text: $foo.name
-- ftd.text: $foo.age
-- ftd.text: $foo.gender
Lang:
ftd
Step - 3 : Creating .json (for example, foo.json)
{
  "name": "arpita",
  "age": 15,
  "gender": "female"
}
Lang:
ftd
Step - 4 : Output
arpita
15
female
Lang:
ftd
NOTE : It will throw an error if other than .json file is used.

Support fastn!

Enjoying fastn? Please consider giving us a star ⭐️ on GitHub to show your support!

Getting Help

Have a question or need help?

Visit our GitHub Q&A discussion to get answers and subscribe to it to stay tuned.

Join our Discord channel and share your thoughts, suggestion, question etc.

Connect with our community!

Found an issue?

If you find some issue, please visit our GitHub issues to tell us about it.

Join us

We welcome you to join our Discord community today.

We are trying to create the language for human beings and we do not believe it would be possible without your support. We would love to hear from you.
Copyright © 2023 - FifthTry.com