docs: def maybe_print_as_json(opts, data, page_info=None):
      """Maybe print data as JSON."""
      if opts.output not in ("json", "pretty_json"):
          return False
  
      root = {"data": data}
  
      if page_info is not None and page_info.is_valid:
          meta = root["meta"] = {}
          meta["pagination"] = page_info.as_dict(num_results=len(data))
  
      if opts.output == "pretty_json":
          dump = json.dumps(root, indent=4, sort_keys=True)
      else:
          dump = json.dumps(root, sort_keys=True)
  
      click.echo(dump)
      return True