convert array data to json
777918
private function dataToJson($data)
        {
            $cols = $this->getColumns($data);

            $rows = [];

            foreach ($data as $key => $row) {
                if ($key != 0 || !$this->_skipFirstRow) {
                    $c = [];

                    foreach ($row as $v) {
                        $c[] = ['v' => $v];
                    }

                    $rows[] = ['c' => $c];
                }
            }

            return json_encode(['cols' => $cols, 'rows' => $rows]);
        }
14929
function convertToJson(callback) {
    var output = new File(file);
    output.contents = new Buffer(JSON.stringify(spritesheet, null, '\t'));
    output.path = file;
    this.push(output);
    callback();
  }
1185196
public function toJson() {
		$array = array("types"=>array());
		foreach ($this->types as $type) {
			$array["types"][] = $type->toJson();
		}
		if ($this->warningMessage) {
			$array["warning"] = $this->warningMessage;
		}
		return $array;
	}
768995
function parseJSON(data) {
    var oData;
    try {
        oData = JSON.parse(data);
    } catch (e) {
        return false;
    }
    return oData;
}
83762
function jsonSerialize() {
		$array = $this->toArray();
		foreach (static::$_columns as $column_name => &$type) {
			if (!isset($array[$column_name])) {
				continue;
			}
			$value = &$array[$column_name];

			if ($type === Model::COLUMN_TYPE_BOOLEAN) {
				if (0 === $value) {
					$value = false;
				} elseif (1 === $value) {
					$value = true;
				}
			} else if (
				$type === Model::COLUMN_TYPE_TIMESTAMP
				|| $type === Model::COLUMN_TYPE_INTEGER_TIMESTAMP
			) {
				if (!$value) {
					$array[$column_name] = null;
					continue;
				}
				if (!is_int($value)) {
					$value = strtotime($value);
				}
				if (!is_int($value)) {
					throw new RuntimeException('Error parsing date "' . $array[$column_name] . '"');
				}
				$value = date('c', $value);
			}
		}
		return $array;
	}
273648
function toArray(obj) {
    var key, val, arr = [];
    for (key in obj) {
        val = obj[key];
        if (Array.isArray(val))
            for (var i = 0; i < val.length; i++)
        arr.push([ key, val[i] ]);
        else
            arr.push([ key, val ]);
    }
    return arr;
}
677383
def to_json(data, pretty):
    
    if pretty:
        return json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
    return json.dumps(data)
318859
public function toJsonArray() {
        $array = $this->_properties;
        foreach ($array as $key => $value) {
            if (in_array($key, $this->fields) && !is_null($value)) {
                $parser = $this->getParser($key);
                $array[$key] = $parser->unparse($value);
            }
            else unset($array[$key]);
        }
        return $array;
    }
489488
function convertObjectToJSON(data) {
      const delimiter = '_'
      let result = {}
      let arrays = {}
      data.forEach(item => {
        const value = item.value
        if (value !== '') {
          if (!item.name) return
          let name = item.name
          let nameParts = name.split(delimiter)
          let currResult = result
          for (let j = 0; j < nameParts.length; j++) {
            const namePart = nameParts[j]
            let arrName
            if (namePart.indexOf('[]') > -1 && j === nameParts.length - 1) {

              arrName = namePart.substr(0, namePart.indexOf('['))
              if (!currResult[arrName]) {
                currResult[arrName] = []
              }
              currResult[arrName].push(value)
            } else {
              if (namePart.indexOf('[') > -1) {
                arrName = namePart.substr(0, namePart.indexOf('['))
                const arrIdx = namePart.replace(/^[a-z]+\[|\]$/gi, '')
                if (!arrays[arrName]) {
                  arrays[arrName] = {}
                }
                if (!currResult[arrName]) {
                  currResult[arrName] = []
                }
                if (j === nameParts.length - 1) {
                  currResult[arrName].push(value)
                } else {
                  if (!arrays[arrName][arrIdx]) {
                    currResult[arrName].push({})
                    arrays[arrName][arrIdx] = currResult[arrName][currResult[arrName].length - 1]
                  }
                }
                currResult = arrays[arrName][arrIdx]
              } else {
                if (j < nameParts.length - 1) {
                  if (!currResult[namePart]) {
                    currResult[namePart] = {}
                  }
                  currResult = currResult[namePart]
                } else {
                  currResult[namePart] = value
                }
              }
            }
          }
        }
      })
      return result
    }
913814
public function renderJson($data=null)
    {
        $this->beforeRender($data);
        
        $res = ErrorInfo::instance($this->responseData())->all();
        
        foreach ($res as $k => $v) {
            if ($v instanceof Collection) {
                $res[$k] = $v->all();
            }
        }
        
        if ($callback = $this->input('callback')) {
            $string = $callback . '(' . json_encode($res) . ')';
        } else {
            $this->response = $this->response->withHeader('Content-Type', 'application/json;charset=utf-8');
            $string = json_encode($res);
        }
        
        return $this->renderText($string);
    }
420306
protected function jsonResponse($data = array())
    {
        $this->view->disable();
        $this->response->setContentType('application/json', 'UTF-8');

        return $this->response->setJsonContent($data);
    }
92273
private function convertSerializedToArray($data)
    {
        $data = @unserialize($data);

        // Maybe the response was a serialized JSON string
        // So let's try to convert that to an array...
        if (is_string($data))
        {
            return $this->convertJsonToArray($data);
        }

        // It could be an object or an array of object
        // but we want a associative array, so use
        // JSON to encode it and then decode it properly...
        if ((is_object($data) or is_array($data)) and $json = $this->convertToJson($data))
        {
            return $this->convertJsonToArray($json);
        }

        return null;
    }
45560
function encode(data) {
  var encodedData = null;
  try {
    encodedData = JSON.stringify(data);
  } catch (err) {
    logger.warn('failed encoding data', data);
  }
  return encodedData;
}
292950
public static function toJson($data, $options = array())
    {
        // Merge options with defaults
        $defaults = array('hide' => array('password'));
        $options = array_merge($defaults, $options);

        // Convert the data to an array, if possible..
        if (!is_array($data)) {
            $data = Arr::convert($data);
        }

        foreach ($data as $k => $v) {
            $data[$k] = Arr::convert($v);
        }

        // Remove the parts we don't want...
        if (isset($options['hide']) and is_array($data)) {
            $data = Arr::removeKeys($data, $options['hide']);
        }

        return json_encode($data);
    }
470158
public function toArrayAll()
    {
        $data = $this->toArray();

        foreach(self::$jsonable as $key){

            if(isset($data[$key]) && Utils::isJson($data[$key])){
                $data[$key] = json_decode($this->{$key});
            }
        }

        return $data;
    }
839764
def serialize_to_json(data, **kwargs):
    
    kwargs['cls'] = kwargs.get('cls', LazyJSONEncoder)

    return json.dumps(data, **kwargs)
1324983
public function toJson()
    {
        $json = null;
        if (!empty($this->toArray())) {
            $json = json_encode($this->toArray());
        }

        return $json;
    }