The legend json can be gotten via an esriRequest to https://SERVER/arcgis/rest/services/SERVICE/legend
Example of a single layer legend info:
{
"layerId": 0,
"layerName": "City Limits",
"layerType": "Feature Layer",
"minScale": 0,
"maxScale": 0,
"legend": [{
"label": "",
"url": "d81c20bbbe11d1b64ebe9ad98f2e9062",
"imageData": "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAADFJREFUOI1jYaAyYKGZgf/+7WugxCAmJqcGFAOpBUYNHDVw1MBRA+lsIKw8o5qB1AIA8kUFF7zjdA0AAAAASUVORK5CYII=",
"contentType": "image/png",
"height": 20,
"width": 20
}]
}
The "layerId" and "legend.url" properties can then be use to form a url for img src.
In the above example:
https://SERVER/arcgis/rest/services/SERVICE/MapServer/0/images/d81c20bbbe11d1b64ebe9ad98f2e9062
with aforementioned properties in bold.
Gets a bit more complicated with categories and renderers.
cmv-app/legendUtil.js at master · cmv/cmv-app · GitHub here's a utility class I use. It's written to back a specific widget but has examples of the requests and handling the responses.