This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/xmldata; | |
public function main() returns error? { | |
// Creates a JSON value. | |
json jsonValue = {"Store": { | |
"@id": "AST", | |
"name": "Anne", | |
"address": { | |
"street": "Main", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/xmldata; | |
public function main() returns error? { | |
// Creates an XML value. | |
xml xmlValue = xml `<Store id="AST"> | |
<name>Anne</name> | |
<address> | |
<street>Main</street> | |
<city>94</city> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/os; | |
public function main() { | |
// Returns the environment variable value associated with the `HTTP_PORT`. | |
string port = os:getEnv("HTTP_PORT"); | |
io:println("HTTP_PORT: ", port); | |
// Returns the username of the current user. | |
string username = os:getUsername(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/xslt; | |
public function main() returns error? { | |
// Gets an `XML` value, which needs to be transformed. | |
xml sourceXml = getXml(); | |
// Gets an `XSL` style sheet represented in an XML value. | |
xml xsl = getXsl(); | |
// Transforms the `XML` content to another format. | |
// For details, see https://lib.ballerina.io/ballerina/xslt/latest#transform. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/uuid; | |
public function main() returns error? { | |
// Tests a string to see if it is a valid UUID. | |
boolean valid = uuid:validate("4397465e-35f9-11eb-adc1-0242ac120002"); | |
io:println("UUID validated: ", valid.toString()); | |
// Detects the RFC version of a UUID. | |
uuid:Version v = check uuid:getVersion( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/uuid; | |
public function main() returns error? { | |
// Generates a UUID of type 1 as a string. | |
string uuid1String = uuid:createType1AsString(); | |
io:println("UUID of type 1 as a string: ", uuid1String); | |
// Generates a UUID of type 1 as a UUID record. | |
uuid:Uuid uuid1Record = check uuid:createType1AsRecord(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/lang.runtime; | |
import ballerina/task; | |
import ballerina/time; | |
// Creates a job to be executed by the scheduler. | |
class Job { | |
*task:Job; | |
int i = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/lang.runtime; | |
import ballerina/task; | |
import ballerina/time; | |
// Creates a job to be executed by the scheduler. | |
class Job { | |
*task:Job; | |
int i = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/lang.runtime; | |
import ballerina/task; | |
// Creates a job to be executed by the scheduler. | |
class Job { | |
*task:Job; | |
int i = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerina/random; | |
public function main() returns error? { | |
// Generates a random decimal number between 0.0 and 1.0. | |
float randomDecimal = random:createDecimal(); | |
io:println("Random decimal number: ", randomDecimal); | |
// Generates a random number between the given start(inclusive) and end(exclusive) values. | |
int randomInteger = check random:createIntInRange(1, 100); |