Encodes a resource state as a JSON string.
If base is provided, converts absolute IRIs (matching isIRI(value, "absolute")) to internal IRIs using internalize, recursively throughout the resource structure. Otherwise, performs plain JSON serialization.
base
isIRI(value, "absolute")
The resource state to encode
Encoding options
The JSON string, with internalized IRIs if base is provided
If resource is not a valid Resource or opts is not a valid CodecOpts
resource
opts
encodeResource( { id: "https://example.com/products/42", name: "Widget", price: 29.99 }, { base: "https://example.com/" });// → '{"id":"/products/42","name":"Widget","price":29.99}' Copy
encodeResource( { id: "https://example.com/products/42", name: "Widget", price: 29.99 }, { base: "https://example.com/" });// → '{"id":"/products/42","name":"Widget","price":29.99}'
decodeResource
Encodes a resource state as a JSON string.
If
baseis provided, converts absolute IRIs (matchingisIRI(value, "absolute")) to internal IRIs using internalize, recursively throughout the resource structure. Otherwise, performs plain JSON serialization.