100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

WebAssembly Text Format

AdvancedLanguage11.9K learners

WebAssembly Text Format (WAT, or WAST) is a human-readable, S-expression-based textual representation of WebAssembly's binary instruction format, used for writing, reading, and debugging WebAssembly modules directly. wasm format that…

Definition

WebAssembly Text Format (WAT, or WAST) is a human-readable, S-expression-based textual representation of WebAssembly's binary instruction format, used for writing, reading, and debugging WebAssembly modules directly. It maps one-to-one with the compact binary .wasm format that browsers and runtimes actually execute.

Overview

WebAssembly (Wasm) is primarily distributed and executed as a compact binary format (.wasm) designed for fast parsing and small file size, which makes it efficient for browsers and other runtimes to load but effectively unreadable to humans. The WebAssembly Text Format exists as the standardized textual counterpart to that binary format, using a Lisp-like S-expression syntax to represent the same module structure — functions, types, imports, exports, memory, and instructions — in a form developers can read, write, and reason about directly. Every valid .wasm binary module can be losslessly converted to and from its .wat textual representation using standard tooling, most commonly the WebAssembly Binary Toolkit (WABT), which provides the wat2wasm and wasm2wat converters, as well as browser developer tools that can display disassembled Wasm as WAT. In practice, very few developers hand-write large WAT programs, since most WebAssembly is produced by compiling from higher-level languages like C, C++, Rust, or Go; WAT is instead primarily used for debugging (inspecting what a compiler actually generated), writing small hand-optimized modules or test cases, teaching the low-level semantics of the WebAssembly instruction set, and generating Wasm programmatically from tools that emit text before assembling it to binary. WAT's syntax reflects WebAssembly's stack-based virtual machine model directly: instructions like i32.add, local.get, and call appear explicitly, and functions, tables, and memories are declared with explicit type signatures. Because WAT is a direct, spec-defined mapping of the binary format rather than a higher-level language, it has no abstractions like variables with inferred types, control-flow sugar, or standard library — it exposes exactly the primitives the WebAssembly virtual machine executes, making it closer in spirit to an assembly language than to a general-purpose programming language.

Key Features

  • S-expression-based syntax representing WebAssembly modules as human-readable text
  • Losslessly convertible to and from the binary .wasm format
  • Standardized as part of the WebAssembly specification itself
  • Directly exposes the stack-based instruction set of the Wasm virtual machine
  • No high-level abstractions — a near 1:1 mapping to binary opcodes
  • Supported by tooling like WABT (wat2wasm/wasm2wat) and browser devtools
  • Used primarily for debugging, teaching, and hand-written low-level modules
  • Rarely hand-written for large programs; usually generated by compilers or disassemblers

Use Cases

Inspecting and debugging compiler-generated WebAssembly output
Writing small, hand-optimized WebAssembly modules or micro-benchmarks
Teaching the low-level semantics of the WebAssembly instruction set
Authoring test fixtures for WebAssembly runtimes and toolchains
Reviewing disassembled Wasm binaries in browser developer tools
Programmatically generating WebAssembly text before assembling to binary

Alternatives

WebAssembly binary format (.wasm)AssemblyScript

Frequently Asked Questions

From the Blog