Variables

The Internet Object document promotes reusability through variables. It allows defining variables that can be applied to simplify schema and definitions, obfuscate values, or reduce the data size. Every key defined in the definition section can be used as a variable.

Types of Variables

Internet Object variables can be categorized into two groups.

  1. Value Variables

  2. Schema Variables

Value Variable

The Value variables are used to directly access and reuse values.

# Defining value variables 
~ record: 123
~ y: yes
~ n: no
~ rgb: [red, green, blue]
---

In the above snippet records, y, n, and rgb are the value variables.

Schema Variable

The schema variables start with $sign and it is used to directly access and reuse schema.

# Defining schema variables
~ $address: {
    street: string, 
    zip: {string, maxLength: 5}, 
    city: string
  }
~ $person: {
    name: string,
    age: int,
    homeAddress?: $address,
    officeAddress?: $address
  }
 ---

In the above code snippet, the schema variable address is reused in another schema variable named person .

Advantages and Use Cases

Reuse Definitions

The value variables and schema variables enable the reuse of definition.

Obfuscate Data

Variables are also used for hiding critical information with modified content to enforce data protection and security.

The following example demonstrates how one can pass critical information over the internet using variables.

The above code snippet represents secrectKey as s and activationKey as a saved on the client-side. This information is securely passed over the internet using variables as shown below,

The receiver will receive the following information without compromising on data security.

Reduce data size

The use of variables helps to reduce the code size as it enables definition reuse that ultimately reduces bandwidth utilization.

In the above code snippet, the schema variable address and accountDetails are used in the person schema definition. So, rather than creating a similar schema multiple times for address it can be created once and reused multiple times in the document.

Improves schema readability

Variables improve schema readability by grouping similar and reusable codes and limiting line length.

Last updated

Was this helpful?