1

I have successfully developed a Joomla 4 API which receives JSON data containing HTML to update the database. - The HTML markup is stripped away when using this code:

$input = $this->input->json->get('data', null, 'json');
$data = json_decode(json_encode($input), false);

How can I make sure the HTML markup stays intact?

1 Answer 1

3

There is no json filter which causes default filter to be applied, stripping away HTML. Use a different filter. This answer shows some examples. Using array filter should work:

$input = $this->input->json->get('data', [], 'array');

Specifically for JSON there is Joomla\Input\Json::getRaw() method which returns the raw JSON string:

$input = $this->input->json->getRaw();
$data = json_decode($input, false);

But be aware it doesn't take manipulations done on the input object into account, data may be outdated.

1
  • 1
    Thanks for the hint with the array. I cast it into an object $data = (object) $input; to get the expected result. Awesome!
    – cappu
    Oct 12, 2023 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.