LogoLogo
HomeCommunityLangstack.comCreate free account
  • 🤝Welcome
  • 🙌Support
  • 💡Get started
    • 📕Learn Langstack
      • Introduction to Langstack
        • Application templates
        • Storage frameworks
        • Account administration
      • Basics and essentials
        • What is an API gateway?
        • How to work with an API gateway
        • What is an Entity?
        • What is an Action box?
          • How to create and work with Action boxes
          • How to perform search in Actions
        • What is an Action?
          • How to create and work with Actions
          • Error propagation
          • Actions in Langstack applications
        • What is a Data type?
          • Simple Data types
        • What is a Variable?
          • Naming rules of a Variable
        • What is a Function?
          • Working with Functions
        • Navigating to a Variable or a Function
        • Implicit Type Conversion (ITC)
        • Explicit Type Conversion
        • Implicit and Explicit Type Conversion for Json
        • Next Steps
      • User management
        • What is a Privilege?
        • What are Groups?
        • What are Users?
      • Introduction to REST API
        • API Name
        • API Group name
        • Request and Response body
          • Request body
          • How to create and work with a Request body
          • Response body
          • How to create and work with a Response body
        • Query strings
          • How to create and work with Query strings
        • Headers
          • How to create and work with Headers
        • Path parameter
        • Create your first API: "Hello World!"
          • Working with API options
        • Exercise 1: GET REST API & Return Response Object
          • Step 1: Create API
          • Step 2: Test the API
        • Exercise 2: Delete a published API
        • Next Steps
      • Introduction to Entities
        • Fields
        • Records
        • Relations
        • Options for an Entity
        • Exercise 1: Customer Accounts and Activities
          • Customer accounts
            • Step 1: Create the Customers Entity
            • Step 2: Create the API
            • Step 3: Update entity through API
          • Customer Activities
            • Step 1: Create the Activities entity
            • Step 2: Create a “1 to Many” relation
            • Step 3: Create the API
            • Step 4: Update entity through API
        • Exercise 2: Customer Records
          • Step 1: Create the API
          • Step 2: Test the API
        • Next Steps
      • Programming with Entities
        • Create
        • Read
        • Update
        • Delete
        • JXPResponse
        • Next Steps
      • Using Triggers
        • After Create Trigger
        • After Update Trigger
        • After Delete Trigger
        • Exercise: Entity & Entity triggers
        • Step 1: Define “After Create” Trigger
        • Step 2: Define “After Update” Trigger
      • Connectors
        • Create a connector
        • SFTP Connector
        • MySQL Connector
        • Next Steps
      • Introduction to ETL pipeline
        • Create an ETL pipeline
        • Data Formats in ETL pipeline
          • Reader
          • Writer
          • Field mapping
        • Shared variables for ETL pipeline
        • ETL functions execution sequences overview
        • Displaying Functions
        • How to perform Search in ETL pipeline
        • Exercise 1: Skip Customer records
          • Step 1: Create the ETL pipeline
          • Step 2: Skip records based on Customer_ID
          • Step 3: Store skipped records in a list
          • Step 4: Store the Skipped Customer record
        • Exercise 2: ETL pipeline, CSV source & FTP Connector
        • Exercise 3: ETL pipeline, Database Source & MySQL Connector
        • Exercise 4: ETL pipeline, CSV Source & FTP Connector using Sections
          • Step 1: Create the ETL pipeline
          • Step 2: Reformat the Join_Date Values and define added fields
      • Multiple Executions, Time Duration, Linked App and Execution Status
        • Skip execution while in progress
        • Time duration settings
        • Linked App
        • Options for Delay Types
        • Execution status
      • Validation pipeline
        • Sequence of Validation pipeline
        • Exercise: Customer Information
          • Step 1: Create a Validation pipeline
          • Step 2: Create the API gateway
          • Step 3: Test the Validation pipeline
      • Introduction to Process
        • Create a process
        • Shared variables for a process
        • Exercise: Customer Anniversary Email Activity
          • Step 1: Check if the join date matches the current date
          • Step 2: Test the Process
      • Introduction to Flows & Flow components
        • What is a Flow?
        • What is a Flow component?
          • What is a Flow component Event?
        • Exercise 1: Customer Anniversary Email
          • Step 1: Create the Flow component
          • Step 2: Create the Flow
          • Step 3: Trigger the Flow
          • Step 4: Check records in the target entity
        • Exercise 2: Store list of customers
          • Step 1: Create the Flow component
          • Step 2: Create the Flow
          • Step 3: Create the API
    • 🌍Tour of Langstack (coming soon)
  • 📘In depth learning
    • 📖User Manual (coming soon)
    • 🔗Connectors
      • MS-SQL connector
        • Data type conversions between Langstack and MSSQL
        • Handling data loss in data type conversions
        • Setting up MS-SQL connector
        • MS-SQL connector as Reader and Writer
        • Using MS-SQL connector in ETL pipeline
          • MS-SQL connector as a source
          • MS-SQL connector as a destination
      • Google Drive connector
        • Set up Google Drive Connector
        • Adding Google Drive path in ETL pipeline Streams
        • Setting up GCP Account, GCP Project, API Enablement, and Credentials (Prerequisites)
          • OAuth 2.0 Client Credentials
          • Service Account Key Credentials
          • API Key Credentials
          • Authorization through Redirect URLs
        • Using Google Drive connector in ETL pipeline
          • Specifying file or folder paths
            • Direct file link
            • Folder link and file name
            • Folder path and file name
            • Folder path excluding file name
            • Folder path including file name
          • Google Drive connector as a source
          • Google Drive connector as a destination
      • AWS connector
        • Introduction
        • Set up AWS S3 Connector
          • OAuth 2.0 Client Type
          • Access Key
          • Public
        • Setting up AWS Account
          • Retrieve Client ID and Client Secret
        • Set up Amazon Web Services (Cognito) Console
          • Retrieve Identity Pool Id
          • Manage Permissions for Roles
          • Adding Redirect URL in Amazon Developer Console
          • User Consent for OAuth 2.0 Client through Login with Amazon
          • Retrieve Access Key Credentials
        • Creating a bucket in AWS
        • Using S3 connector in ETL pipeline
          • Specifying paths
          • Examples
            • AWS S3 connector as a source
            • AWS S3 connector as a destination
      • OneDrive connector
        • Set up OneDrive Connector
        • Setting up Microsoft Azure Account
        • Add URL to Authorized Redirect URLs
        • User Consent for Establishing OneDrive Connection
        • Usage of OneDrive Connector in ETL pipeline
          • Examples
          • OneDrive connector as a source
          • OneDrive connector as a destination
      • Dropbox connector
        • Set up Dropbox Connector
        • Setting up Dropbox Account
        • Add URL to Authorized Redirect URLs
        • User Consent for Establishing Dropbox Connection
        • Usage of Dropbox connector in ETL pipeline
          • Dropbox connector path settings
          • Examples
            • Dropbox connector as a source
            • Dropbox connector as destination
  • 🗃️Use Cases (Coming soon)
    • Use Case 1
    • Use Case 2
    • Use Case 3
Powered by GitBook
On this page
  1. Get started
  2. Learn Langstack
  3. Basics and essentials

Implicit and Explicit Type Conversion for Json

PreviousExplicit Type ConversionNextNext Steps

Last updated 2 years ago

A JSON can read and contain the following data types:

  • String

  • Boolean

  • Numeric

JSON addresses and treats every element within as a JSON. This specification means that any data type it contains is treated as JSON. The same applies to JSON lists.

Due to this specification, JSON can hold heterogeneous lists. i.e., lists that are made up of multiple data types. However, from the perspective of JSON, it is a homogenous list (as all data types are of one type i.e., JSON.)

This design of JSON may term Json as a loose Type data structure. However, Langstack, as a visual, no code programming language, is strongly typed. To work with JSON in Langstack applications, users should be aware that implicit type conversions for JSON are per the rules of Langstack implicit conversions. This ensures that users are protected from unprecedented type changes that may impact any information negatively.

To prevent users from making accidental mistakes assigning different types, Langstack applications keep track of the data types boolean, numeric, string, and Lists types. Therefore, a boolean JSON key can only take a value of a boolean data Type, a string JSON key can only take a value of a string data Type, and so on. The same applies to lists. Hence, a JSON list of strings can only add strings to its list and can only be assigned to another list of strings.

If a user wants to assign data of the type different from the data type defined for the JSON key, the user will be prompted with an alert. Suppose the user still wants to continue with the assignment. In that case, Langstack applications allow it through the explicit conversion functions as in the examples below:

  • GUID and DateTime: can be assigned to Strings after explicit conversion to the type Strings using toString() function.

  • TimeStamp: can be assigned to Numerical after explicit conversion to the type Numerical using toNumerical() function.

  • All other, complex data types such as, JXPResponse can be assigned to a JSON by calling the function toJson().

Example

Consider a JSON variable "JS1" with the key "customers", which is a list of JSONs:

{
  "customers" :[
       {
           "firstname": "string",
           "isActive": true,
           "lastLoginInDays" : 10
       }
   ]
}

The key customers is a list of JSONs that has three keys:

- "firstname" with the data type String

- "isActive" with the data type Boolean

- "lastLoginInDays" with the data type Numerical

  • Create a new variable as follows: Variable name: "JSCustomer" of JSON data type. Click [Sample] to add the sample.

  • Type in the following JSON sample and click [Save]:

{
  "firstname": "string",
  "isActive": true,
  "lastLoginInDays" : 10
}
  • Update the JSON keys with the values of the same type as of the keys:

    • "firstname": "John Doe"

    • "isActive": true

    • "lastLoginInDays" : 5

It immediately accepts updating the "JSCustomer" variable of JSON data type with string, boolean and numeric values as follows:

{"firstname":"John Doe","isActive":true,"lastLoginInDays":5.0}

  • If the user tries to assign a GUID value to “firstname,” which is of the String data type, the user will be prompted regarding the required data type.

If the user still wants to assign the GUID to the firstname field, the user must convert the GUID explicitly to a String data type using the toString() function: GUID.newGUID().toString()

  • The same applies to DateTime. If the user tries to assign a DateTime value to “firstname”, which is of the String data type, the user will be prompted with an alert regarding the required data type:

If the user still wants to assign the DateTime to "firstname", the user must convert the DateTime explicitly to the String data type using the toString() function:

DateTime.Now().toStriSuppose the user tries to assign a TimeStamp value to “lastLoginInDays”, which is of the Numerical data type. In that case,

  • If the user tries to assign a TimeStamp value to “lastLoginInDays”, which is of the Numerical data type, the user will be prompted with an alert regarding the required data type:

If the user still wants to assign the TimeStamp value "lastLoginInDays" field, the user must convert it to Numerical data type using the toNumerical() function:

TimeStamp.Now().toNumerical()

  • Now, add the variable “JSCustomer” (Json) to another variable “JSLstCustomers” (of data type List i.e. list of JSONs) through the Action “Add item to List”.

Here, if the user wants to assign a variable “lstGUID” (containing a list of GUID values) to the variable “JSLstCustomers”, the user will be prompted with an alert.

If the user still wants to assign the “lstGUID” to the variable “JSLstCustomers”, the user must convert it to JSON list data type using the toJsonList() function: lstGUID.toJsonList()

💡
📕