Welcome to JLD2.jl

JLD2.jl is a high-performance, pure Julia library for saving and loading arbitrary Julia data structures. It's designed as a fast binary serialization format that produces files according to the well-known HDF5 format but doesn't rely on external libraries like the HDF5 C-library โ€” making it an ideal choice for native Julia workflows.


๐Ÿ“ฆ What is JLD2.jl?

JLD2 stands for Julia Data Format 2, a file format and serialization library tailored to work seamlessly with native Julia types. Whether you're working with arrays, dictionaries, structs, or custom types, JLD2 provides a reliable way to store your data to disk and retrieve it later โ€” all in pure Julia.


๐Ÿš€ Why Use JLD2?

  • โœ… Save and load any Julia type, including custom structs
  • โœ… Fast and efficient, thanks to native Julia code
  • โœ… Custom IO support โ€” can read and write to either Vector{UInt8} or custom IO implementations
  • โœ… Portable within Julia versions โ€” great for caching, prototyping, and long-term storage
  • โœ… Customizable type loading โ€” offers fine-grained control to update outdated stored structures upon load

โœจ Example: Saving and Loading Data

using JLD2

# Some sample data
model = (name = "Transformer", layers = 12, params = 300_000_000)
scores = [0.91, 0.87, 0.93]

# Save to a file
@save "model_state.jld2" model scores

# Load back later
@load "model_state.jld2" model scores

println(model.name)  # Output: Transformer

You can also save individual variables or load just what you need:

@save "data.jld2" a=1 b=[1,2,3] c="hi"
@load "data.jld2" b c

Below is a comparison of JLD2 and other common Julia libraries for data storage and serialization. Choose the tool that best fits your needs:

LibraryBest ForNotes
JLD2.jlNative Julia data (structs, arrays, Dicts, etc.)Fast, flexible, pure Julia, HDF5-compatible, no external dependencies
Serialization.jlAny Julia objectBuilt-in, very fast, but not cross-version safe or portable outside Julia
MAT.jlInterop with MATLAB .mat filesRead/write MATLAB files, good for sharing with MATLAB users
HDF5.jlFull-featured HDF5 accessDirect interface to HDF5 C library, cross-language, supports advanced HDF5 features
Arrow.jlTabular data, dataframes, analyticsExcellent for columnar data, cross-language (Python, R, etc.), DataFrame support
CSV.jlLightweight table exports/importsGreat for human-readable, row-based data, simple and widely supported
JSON.jlWeb services, config files, nested dictsPortable, text-based, less efficient for complex Julia types

If your goal is to store structured tables (like DataFrames) for analysis or sharing between tools, Arrow.jl or CSV.jl may be a better fit. But if you're dealing with rich, nested, Julia-native data, or just want a fast way to persist your models, simulations, or internal state, JLD2 is the right tool.


๐Ÿ’ฌ Contributing

JLD2 is community-driven! We welcome contributions, bug reports, and suggestions at the GitHub repository.

If you're interested in improving documentation, fixing issues, or proposing new features, weโ€™d love your help.


๐Ÿงญ Next Steps

Use the sidebar to navigate: