Lumesh Parsing Functions Documentation
Function Overview
Function Category | Function Name | Call Format | Description |
---|---|---|---|
Data Parsing | json |
parse.json json_str |
Parse a JSON string into Lumesh data structure |
Data Parsing | toml |
parse.toml toml_str |
Parse a TOML string into Lumesh data structure |
Data Parsing | csv |
parse.csv csv_str |
Parse a CSV string into Lumesh data structure |
Code Parsing | expr |
parse.expr lumesh_code |
Parse a Lumesh code string into an executable expression |
Command Parsing | cmd |
parse.cmd [headers...] output |
Parse command line output into structured data |
Data Serialization | to_json |
parse.to_json expr |
Serialize Lumesh data structure into a JSON string |
Data Serialization | to_toml |
parse.to_toml expr |
Serialize Lumesh data structure into a TOML string |
Data Serialization | to_csv |
parse.to_csv expr |
Serialize Lumesh data structure into a CSV string |
JSON Query | jq |
parse.jq json_str |
Perform common JSON queries, supporting pipes, attributes, indices, and select |
Detailed Descriptions and Examples
1. parse.toml
Parameters:
toml_str
: String type, containing valid TOML content
Output Example:
parse.toml "name = 'Alice'\nage = 30" |
To convert back to a string, use parse.to_toml
on the expression.
2. parse.json
Parameters:
json_str
: String type, containing valid JSON content
Nested Structure Output:
parse.json '{"name":"Alice","hobbies":["reading","swimming"]}' |
To convert back to a string, use parse.to_json
on the expression.
3. parse.csv
Parameters:
csv_str
: String type, containing valid CSV content
Nested Structure Output:
parse.csv "Product Name,Category,Price,Stock |
To convert back to a string, use parse.to_csv
on the expression.
4. parse.expr
Parameters:
lumesh_code
: String type, containing valid Lumesh syntax
Dynamic Code Execution:
let code = "x -> math.max(x, 5)" |
5. parse.cmd
Parameter Modes:
Mode | Example | Description |
---|---|---|
Auto Detection | parse.cmd output |
Smartly detects headers and data rows |
List Headers | parse.cmd [h1, h2] output |
Specify a list of headers |
Multiple Parameters | parse.cmd h1 h2 ... output |
Directly specify multiple headers |
Table Output Example:
parse.cmd(["ID", "NAME", "AGE"], "1 Alice 30\n2 Bob 25") |
Complex Structure Output:
parse.cmd "ITEM QTY PRICE |
6. parse.jq
Parameters:
query_str
: String type, containing valid JSON queries, supporting pipes, attributes, indices, and select
Pipe:|
Attribute Access:.name
Wildcard:.[]
returns the entire array
Select statements support basic comparison operators:>, <, >=, <=, ==, !=
json_str
: String type, containing valid JSON content
let a = '[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]' |
Special Case Handling
Pre-structured Data Recognition
parse.cmd "1, 2, 3" |
Header Auto-conversion
parse.cmd "CPU% MEM(MB) MAJ:MIN\n50 1024 259:0" |
Empty Input Handling
parse.toml "" ; => none |
Best Practices
parse.cmd
is generally used to convert the results of system commands from strings to structured tables.
ps aux | head -n4 | parse.cmd() |
parse.cmd
is often used in conjunction withwhere
andselect
statements.
ps aux | parse.cmd() | where(COMMAND ~: "lume") | select "%CPU" COMMAND RSS |
- Lumesh’s built-in module commands do not require
parse.cmd
conversion and can directly usewhere
andselect
.
fs.ls -l -k | where(size > 8) |