Replace the empty array by empty map.

@param string   $json      The original JSON
@param string[] $arrayKeys The list of keys to be retained with an array representation if they are empty

@return string
340930
private static function replaceArrayByMap($json, array $arrayKeys)
    {
        preg_match_all(self::ARRAY_KEYS_REGEX, $json, $matches, PREG_SET_ORDER);

        foreach ($matches as $match) {
            if (!\in_array($match[1], $arrayKeys, true)) {
                $replace = str_replace('[]', '{}', $match[0]);
                $json = str_replace($match[0], $replace, $json);
            }
        }

        return $json;
    }
1060825
public static function removeKeys($array, $removeKeys)
    {
        $result = [];
        if (!is_array($removeKeys)) {
            $removeKeys = [$removeKeys];
        }
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $value = self::removeKeys($value, $removeKeys);
            }
            if (in_array($key, $removeKeys)) {
                continue;
            } else {
                $result[$key] = $value;
            }
        }
        return $result;
    }
824148
public function replaceAllKeys(array $keys): self
    {
        return static::create(
            \array_combine($keys, $this->getArray()),
            $this->iteratorClass,
            false
        );
    }
549461
public static function cleanBeforeJson(array $array): array
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $array[$key] = self::cleanBeforeJson($array[$key]);
            }

            if ($array[$key] === '' || null === $array[$key]) {
                unset($array[$key]);
            }
        }

        return $array;
    }
187115
private static JsonArray getJsonArray(List<String> keys) {
        JsonArray array = new JsonArray();
        for (String key : keys) {
            array.add(key);
        }

        return array;
    }
99884
public function map($json, $object)
    {
        foreach ($json as $key => $jvalue) {
            $key = $this->getSafeName($key);
            $setter = 'set' . $this->getCamelCaseName($key);
            if (method_exists($object, $setter)) {
                $object->{$setter}($jvalue);
            }
        }

        return $object;

    }
652023
private function traverse(&$json, array $pointerParts)
    {
        $pointerPart = array_shift($pointerParts);

        if (is_array($json) && isset($json[$pointerPart])) {
            if (count($pointerParts) === 0) {
                return $json[$pointerPart];
            }
            if ((is_array($json[$pointerPart]) || is_object($json[$pointerPart])) && is_array($pointerParts)) {
                return $this->traverse($json[$pointerPart], $pointerParts);
            }
        } elseif (is_object($json) && in_array($pointerPart, array_keys(get_object_vars($json)))) {
            if (count($pointerParts) === 0) {
                return $json->{$pointerPart};
            }
            if ((is_object($json->{$pointerPart}) || is_array($json->{$pointerPart})) && is_array($pointerParts)) {
                return $this->traverse($json->{$pointerPart}, $pointerParts);
            }
        } elseif (is_object($json) && empty($pointerPart) && array_key_exists('_empty_', get_object_vars($json))) {
            $pointerPart = '_empty_';
            if (count($pointerParts) === 0) {
                return $json->{$pointerPart};
            }
            if ((is_object($json->{$pointerPart}) || is_array($json->{$pointerPart})) && is_array($pointerParts)) {
                return $this->traverse($json->{$pointerPart}, $pointerParts);
            }
        } elseif ($pointerPart === self::LAST_ARRAY_ELEMENT_CHAR && is_array($json)) {
            return end($json);
        } elseif (is_array($json) && count($json) < $pointerPart) {
            // Do nothing, let Exception bubble up
        } elseif (is_array($json) && array_key_exists($pointerPart, $json) && $json[$pointerPart] === null) {
            return $json[$pointerPart];
        }
        $exceptionMessage = sprintf(
            "Json Pointer '%s' references a nonexistent value",
            $this->getPointer()
        );
        throw new NonexistentValueReferencedException($exceptionMessage);
    }
716183
private static function stringifyArrayKey(array $key): string
    {
        ksort($key);

        foreach ($key as &$value) {
            if (is_array($value)) {
                $value = self::stringifyArrayKey($value);
            } elseif (is_object($value)) {
                $value = self::stringifyKey($value);
            }
        }

        return json_encode($key);
    }
1358684
public static function getObjectWithKey(array $array, $key)
    {
        foreach ($array as $object) {
            if (is_array($object) && array_key_exists($key, $object)) {
                return $object;
            }
        }

        return null;
    }
152559
public function toJson($key = null, $options = 0)
    {
        if (is_string($key)) {
            return json_encode($this->get($key), $options);
        }
        $options = $key === null ? 0 : $key;
        return json_encode($this->elements, $options);
    }
764487
public static function createFromJson(string $json): self
    {
        $data = \json_decode($json, true);
        if (!\is_array($data)) {
            throw new InvalidArgumentException('Invalid argument.');
        }

        return self::createFromKeyData($data);
    }
1286169
public static function replaceArrayKeys($dataArray, $oldKeyPattern, $newKey)
    {
        $effect = [];

        if (is_array($dataArray) && !empty($dataArray)) {
            foreach ($dataArray as $key => $value) {
                if (preg_match($oldKeyPattern, $key)) {
                    $key = $newKey;
                }

                if (is_array($value)) {
                    $value = self::replaceArrayKeys($value, $oldKeyPattern, $newKey);
                }

                $effect[$key] = $value;
            }
        }

        return $effect;
    }
159736
public static function fromArray(array $json)
    {
        $request=new MRPCJsonRequest();
        
        $request->setId($json["id"]);
        $request->setId($json["method"]);
        $request->setId($json["params"]);
        
        return $request;
    }
218660
public static function expandKey(array $array, string $key): array
	{
		if(strpos($key, '*') === false)
		{
			throw new RuntimeException('The key must contain at least one wildcard character.');
		}

		$keys = (array) $key;

		start:

		$expanded = [];

		foreach($keys as $key)
		{
			[$first, $remaining] = array_map('trim', explode('*', $key, 2), ['.', '.']);

			if(empty($first))
			{
				$value = $array;
			}
			elseif(is_array($value = static::get($array, $first)) === false)
			{
				continue;
			}

			foreach(array_keys($value) as $key)
			{
				$expanded[] = trim($first . '.' . $key . '.' . $remaining, '.');
			}
		}

		if(strpos($remaining, '*') !== false)
		{
			$keys = $expanded;

			goto start;
		}

		return $expanded;
	}
807495
public function createCacheKey($keys) {
        if (is_array($keys)) {
            $key = array_shift($keys);

            if ($keys) {
                foreach ($keys as $value) {
                    if (is_array($value)) {
                        $key .= '-' . md5(json_encode($value));
                    } else if ($value) {
                        $key .= '-' . $value;
                    }
                }
            }
        } else {
            $key = $keys;
        }

        return (string) $key;
    }
331711
static function filterByKeys($array, $requiredKeys) {
		if (is_array($array)) {
			return array_intersect_key($array, array_fill_keys($requiredKeys, true));
		}
		if ($array instanceof \ArrayAccess) {
			$ret = array();
			foreach ($requiredKeys as $k) {
				if (isset($array[$k])) {
					$ret[$k] = $array[$k];
				}
			}
			return $ret;
		}

		throw new \InvalidArgumentException("Argument must be an array or object with ArrayAccess");
	}
1009606
public static function replace_key(array $array, $oldKey, $newKey) : array
  {
    $newArray = array();

    foreach ($array as $key => $value) {
      if ($key == $oldKey) {
        $newArray = array_merge($newArray, [$newKey => $value]);
      } else {
        $newArray = array_merge($newArray, [$key => $value]);
      }
    }

    return $newArray;
  }