V8-archive: Warning after json API response for json and array field types

Created on 14 Jun 2019  Â·  4Comments  Â·  Source: directus/v8-archive

Bug Report

When I have a field set to json or array and post something to that collection, it will execute the post but add the following warning after the json response:

{
... the expected json object of the collection
}
<br/ > ↵ < b > Warning </b>:  strlen() expects parameter 1 to be string, array given in <b>/api/ src/core/Directus/Services/AbstractService.php </b> on line <b>500</b> <br / > ↵

I get the same error when using the app to update in some collections. The error reads:

API returned invalid JSON

when i inspect it it's because of the same error as above: first the JSON object, then the error message.

Steps to Reproduce

  1. set up a collection with an array field and/or json field (for interfaces tags or code)
  2. API post to collection
  3. see response

Expected Behavior

Just correct json response

Actual Behavior

json response plus added error message

Technical Details

Latest build branch of the API

  • Device: Desktop
  • OS: MAC
  • Web Server: MAMP / Apache
  • PHP Version: 7.2.8
  • Database: [eg: MySQL 8.0.12]
  • Install Method: cloned api build
bug

Most helpful comment

Hey @Kinzi

If everything will work as per the plan; then we will make it live at today EOD.

All 4 comments

Probably not very elegant but a quick fix is to add:

            $testvalue = '';
            if (is_array($value) || is_object($value)) {
                $testvalue = json_encode($value);
            } else {
                $testvalue = $value;
            }

to src/core/Directus/Services/AbstractService.php in line 500 (beginning of the else clause)

and then change strlen($value) to strlen($testvalue)

Fixed in #1024

@bjgajjar Thanks for fixing - when will this be in the build branch?

Hey @Kinzi

If everything will work as per the plan; then we will make it live at today EOD.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdwmhcc picture cdwmhcc  Â·  3Comments

rijkvanzanten picture rijkvanzanten  Â·  3Comments

metalmarco picture metalmarco  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments

Varulv1997 picture Varulv1997  Â·  3Comments