public static byte[] encode(Tensor tensor, EncodeOptions options) {
        Slime slime = new Slime();
        Function<String, Inserter> target = (key -> new SlimeInserter(slime));
        final Cursor root = options.directValues() ? null : slime.setObject();
        if ( ! options.directValues()) {
            root.setString("type", tensor.type().toString());
            target = (key -> new ObjectInserter(root, key));
        }

        if (options.shortForm()) {
            if (tensor instanceof IndexedTensor denseTensor) {
                if (options.hexForDensePart()) {
                    target.apply("values").insertSTRING(asHexString(denseTensor));
                } else {
                    // Encode as nested arrays if indexed tensor
                    Cursor parent = target.apply("values").insertARRAY();
                    encodeDenseValues(denseTensor, parent);
                }
            } else if (tensor instanceof MappedTensor mapped && tensor.type().dimensions().size() == 1) {
                // Short form for a single mapped dimension
                Cursor parent = target.apply("cells").insertOBJECT();
                encodeSingleDimensionCells(mapped, parent);
            } else if (tensor instanceof MixedTensor mixed && tensor.type().hasMappedDimensions()) {
                // Short form for a mixed tensor
                boolean singleMapped = tensor.type().dimensions().stream().filter(TensorType.Dimension::isMapped).count() == 1;
                if (singleMapped) {
                    encodeLabeledBlocks(mixed, target.apply("blocks").insertOBJECT(), options.hexForDensePart());
                } else {
                    encodeAddressedBlocks(mixed, target.apply("blocks").insertARRAY(), options.hexForDensePart());
                }
            } else {
                // default to standard cell address output
                Cursor parent = target.apply("cells").insertARRAY();
                encodeCells(tensor, parent);
            }

            return com.yahoo.slime.JsonFormat.toJsonBytes(slime);
        }
        else {
            Cursor parent = target.apply("cells").insertARRAY();
            encodeCells(tensor, parent);
        }
        return com.yahoo.slime.JsonFormat.toJsonBytes(slime);
    }
Serializes the given tensor value into JSON format.

@param tensor the tensor to serialize
@param options format options for short/long, wrapped/direct, etc
vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java