JsonldEx

Hex.pmDocumentationDocs WorkflowLicenseCIRelease (precompiled NIFs)

🚀 36x faster than pure Elixir JSON-LD implementations

High-performance JSON-LD processing library for Elixir with Rust NIF backend.

Documentation

Quick API

Notes

Provider selection (canonicalization)

Performance

JsonldEx delivers exceptional performance through its Rust-based NIF implementation:

Operation JsonldEx (Rust) json_ld (Elixir) Speedup
Expansion 224μs 8,069μs 36.0x
Compaction ~200μs* ~7,500μs* ~37x*
Flattening ~180μs* ~6,800μs* ~38x*
*Estimated based on expansion benchmarks. Actual results may vary.

Features

Installation

Add jsonld_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:jsonld_ex, "~> 0.1.0"}
  ]
end

Quick Start

# Expand a JSON-LD document
doc = %{
  "@context" => "https://schema.org/",
  "@type" => "Person",
  "name" => "Jane Doe",
  "age" => 30
}

json_string = Jason.encode!(doc)
{:ok, expanded} = JsonldEx.Native.expand(json_string, [])

# Compact with a context
context = %{"name" => "https://schema.org/name"}
context_string = Jason.encode!(context)
{:ok, compacted} = JsonldEx.Native.compact(expanded, context_string, [])

# Other operations
{:ok, flattened} = JsonldEx.Native.flatten(json_string, nil, [])
{:ok, rdf_data} = JsonldEx.Native.to_rdf(json_string, [])

API Reference

Core Operations

Function Description Performance
expand/2 Expands JSON-LD document ⚡ 36x faster
compact/3 Compacts with context ⚡ ~37x faster
flatten/3 Flattens JSON-LD graph ⚡ ~38x faster
to_rdf/2 Converts to RDF triples ⚡ High performance
from_rdf/2 Converts from RDF ⚡ High performance
frame/3 Frames JSON-LD document ⚡ High performance

Utility Operations

Spec workflow helpers

Why Choose JsonldEx?

Build Notes

macOS Build Issues

If you encounter LTO-related compiler errors on macOS (e.g., options -C embed-bitcode=no and -C lto are incompatible), use:

JSONLD_NIF_FORCE_BUILD=1 mix compile
# or
make macos

This forces local compilation with optimized settings for macOS compatibility. The project has been configured to handle recent macOS/Xcode toolchain changes automatically.

GitHub Releases & Precompiled NIFs

If you're experiencing rustler_precompiled download failures, you can trigger GitHub workflows to generate missing precompiled artifacts:

Quick Fix (Recommended)

# Setup GitHub CLI (one-time)
make gh-setup

# Check current status
make gh-status

# Auto-fix missing artifacts for current version
make gh-fix-missing

Manual Control

# Create new release with precompiled NIFs
make gh-release

# Rebuild precompiled NIFs for existing release
make gh-precompiled

# Check workflow status
make gh-check-releases

What This Does

Requirements

This solves the rustler_precompiled issue by ensuring all target platforms have precompiled artifacts available for download.

URDNA2015 via ssi (optional)

Precompiled NIFs (rustler_precompiled)

Publishing guide

Prerelase workflow (dry run)

RC tag validation checklist

If assets are temporarily missing or you need to build locally, either:

Note: For local builds, ensure your Rust toolchain supports Cargo.lock v4 (cargo --version ≥ 1.79 recommended).

Continuous Integration

Local Preflight (Linux artifacts)

Fail-fast checks

Setup helper

Preflight environment overrides

Suggested cross image tags

Troubleshooting

Common Issues

rustler_precompiled Download Failures

Error: couldn't fetch NIF from https://github.com/.../releases/download/...

Solutions:

  1. Quick fix: make gh-fix-missing (auto-triggers missing artifact builds)
  2. Local build: make macos or JSONLD_NIF_FORCE_BUILD=1 mix compile
  3. Manual trigger: make gh-release to create new release with all artifacts

macOS LTO Compiler Errors

Error: options -C embed-bitcode=no and -C lto are incompatible

Solution: Use local build with make macos - the project is pre-configured for latest macOS/Xcode compatibility.

Missing GitHub CLI

Error: GitHub CLI (gh) not found

Solution: Run make gh-setup to automatically install and configure GitHub CLI.

Authentication Issues

Error: Failed to trigger workflow. Make sure you're authenticated

Solution:

gh auth login
# or
make gh-setup

Workflow Permission Issues

Error: API calls fail with permission errors

Cause: Repository requires write access for release workflows.

Solution: Contact repository maintainers or fork the repository.

Getting Help

  1. Check artifact status: make gh-status
  2. View recent releases: make gh-check-releases
  3. Force local build: make macos
  4. Reset and retry: mix clean && make macos

For persistent issues, please file a GitHub issue with:

License

MIT

spec.apply flags (advanced)

Patch formats supported

Example

mix spec.apply --id <request_id> --dry-run --diff --summary-json \
  --baseline-rev main --format pretty