query
On this page

toJSON

lib.toJSON

Primop
Docs pulled from | This Revision | 31 minutes ago


Nix manual

Takes 1 arguments

e

Return a string containing a JSON representation of e. Strings, integers, floats, booleans, nulls and lists are mapped to their JSON equivalents. Sets (except derivations) are represented as objects. Derivations are translated to a JSON string containing the derivation’s output path. Paths are copied to the store and represented as a JSON string of the resulting store path.

Noogle detected

Aliases

Detected Type
toJSON :: a -> String

Implementation

This function is implemented in c++ and is part of the native nix runtime.

src/libexpr/primops.cc:2625

static void prim_toJSON(EvalState & state, const PosIdx pos, Value ** args, Value & v)
{
    std::ostringstream out;
    NixStringContext context;
    printValueAsJSON(state, true, *args[0], pos, out, context);
    v.mkString(out.view(), context, state.mem);
}

Implementation

The following is the current implementation of this function.

toJSON