Assuming you are using gRPC.
const serialized = new Uint8Array(new Buffer(json));
const mu = new dgraph.Mutation();
mu.setSetJson(serialized);
return txn.mutate(mu).then((res) => {
txn.commit();
console.log(res.getUidsMap().get("blank-0")) . => Like so you can retrieve the UIDs returned from a mutation.
return;
}).catch((e) => {
console.log(e);
return txn.discard();
});