Array_to_Brackets()
Syntax: _Array_to_Brackets(Array_to_Convert)
Purpose: Transforms a multidimensional array into a representation using bracket notation. This format visually displays the structure and nesting of the array.
Example: Its output shows how the array elements are nested, making it easier to understand the relationships within the data.
Array_to_Json()
Syntax: _Array_to_Json(table)
Purpose: Converts a Lua table (which can represent complex data structures) into a JSON-formatted string. JSON is a widely used format for data exchange due to its readability and compatibility across platforms.
Important
Note:
Handling nil
values in tables requires using json.null
to preserve indices in the generated JSON.
Brackets_to_Array()
Syntax: _Brackets_to_Array(String_With_Values_Bracket_Enclosed, Numeric_Values)
Purpose: Extracts values enclosed within brackets and ignores surrounding text. It returns an array containing the extracted values.
Parameters:
String_With_Values_Bracket_Enclosed: The string containing the bracketed values.
Numeric_Values: Boolean (true/false) to indicate if the extracted values should be treated as numbers.
JSON-Related Commands
Json_Decode_From_File()
Syntax: _Json_Decode_From_File(jsonFile)
Purpose: Reads a JSON file from disk and decodes it into a Lua table, allowing you to work with the data in your Lu C Studio project.
Json_Get_Numeric_Field_and_Cut()
Syntax: _Json_Get_Numeric_Field_and_Cut(Json_String_Name, Field_Name)
Purpose: Extracts a specific numeric field from a JSON string and removes it from the original JSON content.
Json_Get_String_Field_and_Cut()
Syntax: _Json_Get_String_Field_and_Cut(Json_String_Name, Field_Name)
Purpose: Similar to the numeric version, but extracts string fields from JSON and removes them.
Json_Prettify()
Syntax: _Json_Prettify(json_encoded_data)
Purpose: Takes JSON data and reformats it for readability, adding indentation and spacing.
Json_to_Array()
Syntax: _Json_to_Array(json_encoded_data)
Purpose: Decodes a JSON string into a Lua table, providing a structured representation of the data.
Let's illustrate with an example:
jsonStr =
'{"menu": {"id": 1, "items": [{"name": "Pizza"}, {"name": "Pasta"}]}}'
-- Decode JSON, and extract the first item's name
decodedTable = _Json_to_Array(jsonStr)
firstItemName = _Json_Get_String_Field_and_Cut(decodedTable,
"name"
)
-- Format for bracket notation and pretty-print the remaining JSON
bracketVersion = _Array_to_Brackets(decodedTable)
prettyJson = _Json_Prettify(decodedTable)