code: def _json_view_data(
      bg_img,
      stat_map_img,
      mask_img,
      bg_min,
      bg_max,
      black_bg,
      colors,
      cmap,
      colorbar,
  ):
      """Create a json-like viewer object, and populate with base64 data.
  
      Returns: json_view
  
      """
      # Initialise brainsprite data structure
      json_view = dict.fromkeys(
          [
              "bg_base64",
              "stat_map_base64",
              "cm_base64",
              "params",
              "js_jquery",
              "js_brainsprite",
          ]
      )
  
      # Create a base64 sprite for the background
      bg_sprite = BytesIO()
      bg_data = safe_get_data(bg_img, ensure_finite=True).astype(float)
      bg_mask, bg_cmap = _get_bg_mask_and_cmap(bg_img, black_bg)
      _save_sprite(
          bg_data, bg_sprite, bg_max, bg_min, bg_mask, bg_cmap, "png"
      )
      json_view["bg_base64"] = _bytesIO_to_base64(bg_sprite)
  
      # Create a base64 sprite for the stat map
      stat_map_sprite = BytesIO()
      data = safe_get_data(stat_map_img, ensure_finite=True)
      mask = safe_get_data(mask_img, ensure_finite=True)
      _save_sprite(
          data,
          stat_map_sprite,
          colors["vmax"],
          colors["vmin"],
          mask,
          cmap,
          "png",
      )
      json_view["stat_map_base64"] = _bytesIO_to_base64(stat_map_sprite)
  
      # Create a base64 colormap
      if colorbar:
          stat_map_cm = BytesIO()
          _save_cm(stat_map_cm, colors["cmap"], "png")
          json_view["cm_base64"] = _bytesIO_to_base64(stat_map_cm)
      else:
          json_view["cm_base64"] = ""
  
      return json_view
  
imports: import copy
  import json
  import os
  import warnings
  from base64 import b64encode
  from io import BytesIO
  import matplotlib
  import numpy
  from matplotlib.image import imsave
  from nibabel.affines import apply_affine
  from nilearn.plotting.html_document import HTMLDocument
  from .._utils import fill_doc
  from .._utils.extmath import fast_abs_percentile
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import check_niimg_3d
  from .._utils.param_validation import check_threshold
  from ..datasets import load_mni152_template
  from ..image import get_data, new_img_like, reorder_img, resample_to_img
  from ..plotting import cm
  from ..plotting.find_cuts import find_xyz_cut_coords
  from ..plotting.img_plotting import load_anat
  from .js_plotting_utils import colorscale, get_html_template
label_desc: Use image node_id 12 for calling a global function with example usage: _json_view_data(bg_img, stat_map_img, mask_img, bg_min, bg_max, black_bg, colors, cmap, colorbar) and returns: json_view