Function Store
  • Home
  • Getting started
    • Introduction
    • Installing a function
    • Reconfiguring a function
    • Uninstalling a function
    • FAQs
  • Reference
    • Requirements
      • Assign Roles
        • User permissions
      • Link a Billing account to your project
      • Enable the APIs
    • Projects
      • How to add a project
      • How to set up a project
    • Functions
      • Benefits
      • Use cases
      • Authentication when installing
      • Runtime configuration
      • Deploying with a ZIP file
    • Policies
      • How to add a Policy
      • How to remove a Policy
    • Authentication
      • Users
      • Roles
      • Permissions
    • Secrets
      • Creating a Secret
      • Using a Secret
      • Changing the value for a Secret
      • Deactivating a Secret
  • developers
    • Overview
    • Getting Started
    • Set up
    • Workspaces
      • Create a workspace
      • Workspace boilerplate
      • Node engines
    • Writing Functions
      • Function Anatomy
      • Configuration file
      • Function Triggers
      • Environment Variables
        • Type "text"
        • Type "number"
        • Type "email"
        • Type "url"
        • Type "json"
        • Type "boolean"
        • Type "select"
        • Type "multiselect"
        • Type "firestoreDocumentPath"
        • Type "firestoreCollectionPath"
        • Type "color"
      • Documentation
    • Push/Update your functions in the cloud
    • Continuous Integration
    • Publish functions in the Marketplace
    • Emulators
      • Initialize emulators in your workspace
      • Environment variables
      • Starting emulators
      • Testing your functions in the emulator
      • Importing existing data into local emulators
        • Exporting data from Cloud Firestore to local emulator
        • Exporting user accounts from Firebase to local emulator
    • Visual Studio Code Extension
      • Installing the extension
      • Extension UI
      • Functions list
      • Creating and editing functions
      • Emulators
      • Extension settings
      • Troubleshooting
        • "Command not found" error when executing a command
  • Billing
    • Understanding Billing
  • Security
    • Security
  • Resources
    • Events and Triggers
    • Best Practices
      • How to log events in functions?
    • Document your Functions
    • Editorial guidelines
    • Our Processes
      • Use Cases Analysis
  • Use cases
    • Custom Stripe Checkout
Powered by GitBook
On this page
  • Example of an environment variable type "json" definition
  • Example of how to consume the value of the environment variable within the function implementation
  • Properties of the type

Was this helpful?

  1. developers
  2. Writing Functions
  3. Environment Variables

Type "json"

PreviousType "url"NextType "boolean"

Last updated 3 years ago

Was this helpful?

Sometimes your function needs more complex data as input: let's say that you need a JSON service account to authenticate against a third-party API. You can use environment variables of type json in your implementation, and then our platform will ask consumers to enter their value during installation.

The type json variables allow the consumers of a function to enter any json object valid, which you need to define using the schema prop. This type is presented in the installation UI form as a JSON input (see image below), but ultimately you can only access them as strings in your function implementation.

Example of an environment variable type "json" definition

"env": [
    {
        "name": "DATA_PROJECTION",
        "description": "The projection in JSON format that will be used to filter the fields that you want to synchronize.",
        "required": true,
        "type": "json",
        "schema": {
            "type": "object",
            "minProperties": 1,
            "patternProperties" : {
                "^.*$" : {
                    "anyOf": [
                        {
                            "type": "integer",
                            "enum": [0, 1]

                        },
                        {
                            "type": "boolean"
                        },
                        {
                            "$ref": "#"
                        }
                    ]
                }
            }     
        }
    }
]

Example of how to consume the value of the environment variable within the function implementation

const myFunction = () => {
    const dataProjection = JSON.parse(process.env.DATA_PROJECTION)
    ...
};

module.exports = myFunction;

Properties of the type

property

type

required

default

description

name

string

yes

-

The name of the environment variable. This should be unique for each variable.

description

string

no

-

The description of the environment variable.

default

json

no

-

The default value for the variable.

required

bool

no

false

Specifies that a variable must be filled out before submitting.

schema

json

yes

-

The schema will define the structure of the expected object when the "type": "json". This prop is required when the "type": "json".