Document:Read Synchronous

Read the contents of a file selected through a document dialog. Use it to import text or binary data after the user selects a file. Decode the returned string separately when the contents are JSON or another structured format.

Syntax
Luau
Document:Read() -> string

Parameters

Call this method with a Document receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

This function takes no arguments.

Returns

string

The file contents as a string. Reading a folder raises an error.

Usage notes

Document is a handle returned by a file dialog or a folder method. Call its methods with a colon, for example document:Read(). After Delete succeeds, that handle is invalid and further method calls raise an error.

Example

Example
Luau
local document = openfiledialog()
if document then
    local ok, settings, message = json.decodeSafe(document:Read())
    if ok then
        print(json.encodePretty(settings))
    else
        print("Not valid JSON:", message)
    end
end
Kawaii documentation