How to read toml file in Ballerina?

60 Views Asked by At

I have some resource files that are in toml format. What is the approach to read a toml file using ballerina language? Also, is there a module for toml for the basic file read/write operations?

1

There are 1 best solutions below

0
On

You can use the ballerina toml module to read/write toml files.

Ex:

import ballerina/toml;
// Parsing a TOML file
map<json>|toml:Error tomlFile = toml:readFile("path/to/file.toml");

// Write the TOML content into a file
map<json> toml = {
    "str": "string",
    "float": 0.01,
    "inline": {
        "boolean": false
    }
};
toml:Error? fileResult = toml:writeFile("path/to/file.toml", toml);

For more details, refer to the API docs.