CodeIgniter Forums
APIResponseTrait JSON_NUMERIC_CHECK - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: APIResponseTrait JSON_NUMERIC_CHECK (/showthread.php?tid=77125)



APIResponseTrait JSON_NUMERIC_CHECK - aybarsm - 07-22-2020

Hello all,

I wonder is there any easy way to achieve putting JSON_NUMERIC_CHECK option while encoding to JSON with API Response Trait.

Kind regards.


RE: APIResponseTrait JSON_NUMERIC_CHECK - jreklund - 07-22-2020

Hi,

What function are you using? Are you using the getJSON?

If so you can make your own $formatters, see /app/Config/Format.php

You need to make a copy of \CodeIgniter\Format\JSONFormatter and replace it with your own.


RE: APIResponseTrait JSON_NUMERIC_CHECK - paulbalandan - 07-22-2020

If you are using the latest version, you can use the $formatterOptions in app/Config/Format.php. Then in the `application/json` key, just include the new set of default flags there, which include `JSON_NUMERIC_CHECK`.