public function test_it_gets_values_according_to_paths() { $jsonPath = new JsonPath(['foo' => ['bar' => ['baz' => 'VALUE_1', 'lol' => 'VALUE_2']]]); $this->assertEquals('VALUE_1', $jsonPath->get('foo.bar.baz')); $this->assertEquals('VALUE_2', $jsonPath->get('foo.bar.lol')); $this->assertNull($jsonPath->get('foo.bar.boo')); }
/** * Populates the actual value into a JSON field, i.e. it has reached the end of the line and no * further nesting is required. * * @param Parameter $param The schema that defines how the JSON field is being populated * @param mixed $userValue The user value that is populating a JSON field * @param array $json The existing JSON structure that will be populated * * @return array|mixed */ private function stockValue(Parameter $param, $userValue, array $json) : array { $name = $param->getName(); if ($path = $param->getPath()) { $jsonPath = new JsonPath($json); $jsonPath->set(sprintf("%s.%s", $path, $name), $userValue); $json = $jsonPath->getStructure(); } elseif ($name) { $json[$name] = $userValue; } else { $json[] = $userValue; } return $json; }