Fix problems with compiling stateful apply to json