Skip to main content

Json

The JSON Module for the addon API!


Functions

isSafe

sm.scrapcomputers.json.isSafe( root )

Returns true if a lua table is safe to convert to JSON.

Arguments:

  • root [ table ] The lua table to check.

Returns:

  • [ boolean ] If true, That means it's safe to convert. else this is not safe to be passed to sm.json.writeJsonString or sm.json.save!

toString

sm.scrapcomputers.json.toString( root, safeMode, prettify, indent )

Converts a lua table to a JSON string.

Arguments:

  • root [ table ] The lua table to convert to a string.
  • safeMode [ boolean? ] If it should care about saftey or not.
  • prettify [ boolean? ] If true, The JSON string would be prettier. Use this when you want to display it to the user.
  • indent [ string? ] The indentation character. Defaults to "\t"

Returns:

  • [ string ] The JSON string from a Lua table.

prettifyTable

sm.scrapcomputers.json.prettifyTable( rootContents )

Adds syntax highlighting to the JSON tab. Content is automatically prettified.

Arguments:

  • rootContents [ table|string|number|boolean|nil ] The root contents to format.

Returns:

  • [ string ] The prettified JSON-like formatted string.

prettifyString

sm.scrapcomputers.json.prettifyString( root )

Prettifies a JSON string by parsing it into a table and passing it into prettifyTable.

Arguments:

  • root [ string ] The raw JSON string.

Returns:

  • [ string ] The prettified result.

toJsonCompatibleTable

sm.scrapcomputers.json.toJsonCompatibleTable( tbl )

Cleans a table by removing all values that cannot be represented in JSON.

Arguments:

  • tbl [ table ] The table to clean. (It will be modified.)

Returns:

  • [ table ] The cleaned table.