Title: TypeError: json_decode() in lib/wfConfig.php(545)
Last modified: November 12, 2021

---

# TypeError: json_decode() in lib/wfConfig.php(545)

 *  Resolved [Micha](https://wordpress.org/support/users/michaing/)
 * (@michaing)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/)
 * I recently face TypeError’s with the plugin, when a login is blocked as brute
   force attempt and tried to be logged, it seems. I suspect this being the case
   since I upgraded to PHP8.1, though it seems to be a bug in the code independently:
 *     ```
       Error message: Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, array given in /var/www/blog/wp-content/plugins/wordfence/lib/wfConfig.php:545
       Stack trace:
       #0 /var/www/blog/wp-content/plugins/wordfence/lib/wfConfig.php(545): json_decode()
       #1 /var/www/blog/wp-content/plugins/wordfence/lib/wfUtils.php(1730): wfConfig::getJSON()
       #2 /var/www/blog/wp-content/plugins/wordfence/lib/wfUtils.php(1615): wfUtils::check_and_log_last_error()
       #3 /var/www/blog/wp-content/plugins/wordfence/lib/wfActivityReport.php(448): wfUtils::IP2Country()
       #4 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3108): wfActivityReport::logBlockedIP()
       #5 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3126): wordfence::checkSecurityNetwork()
       #6 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3098): wordfence::processBruteForceAttempt()
       #7 /var/www/blog/wp-includes/class-wp-hook.php(303): wordfence::authenticateFilter()
       #8 /var/www/blog/wp-includes/plugin.php(189): WP_Hook->apply_filters()
       #9 /var/www/blog/wp-includes/pluggable.php(593): apply_filters()
       #10 /var/www/blog/wp-includes/user.php(95): wp_authenticate()
       #11 /var/www/blog/wp-login.php(1142): wp_signon()
       #12 {main}
       ```
   
 * In `lib/wfConfig.php(545)`, the declared function is:
 *     ```
       getJSON($key, $default = false, $allowCached = true)
       ```
   
 * It hence expects up to three arguments, the second being an optional default 
   JSON to return. In `lib/wfUtils.php(1730)` however it is called like this:
 *     ```
       wfConfig::getJSON($previousKey, array(0, false));
       ```
   
 * Hence as second argument is an array and no JSON, which then causes the type 
   error in `json_decode`. Based on other `getJSON` calls in the code, it is intended
   that the second argument is/can be an array, and if `json_decode` returns `null`,
   it is also returned directly, where a decoded array is expected. But the same
   cannot be used as input to `json_decode`, or course. In the `get` function where
   the JSON string is derived, I changed:
 *     ```
       return $default
       ```
   
 * to
 *     ```
       return @json_encode($default);
       ```
   
 * as a quick and dirty solution so that the default is passed as JSON string into`
   json_decode`, but as array when `json_decode` returns `null`. This back and forth
   however doesn’t look nice and probably it makes more sense to change the `get`
   function to return `null` instead of `$default` so that the input array is always
   returned directly without back and forth decoding/encoding:
 *     ```
                       if (!self::$tableExists) {
                               return null;
                       }
   
                       $table = self::table();
                       if (!($option = $wpdb->get_row($wpdb->prepare("SELECT name, val, autoload FROM {$table} WHERE name = %s", $key)))) {
                               return null;
                       }
       ```
   
 * Best regards,
 * Micha
    -  This topic was modified 4 years, 6 months ago by [Micha](https://wordpress.org/support/users/michaing/).
      Reason: Found further info about how getJSON is intended to be used
    -  This topic was modified 4 years, 6 months ago by [Micha](https://wordpress.org/support/users/michaing/).
    -  This topic was modified 4 years, 6 months ago by [Micha](https://wordpress.org/support/users/michaing/).

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [Micha](https://wordpress.org/support/users/michaing/)
 * (@michaing)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15061973)
 * Subsequent edits of a topic trigger an automatic mark as spam? Please tune this
   algorithm…
 *  Plugin Support [wfpeter](https://wordpress.org/support/users/wfpeter/)
 * (@wfpeter)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15070879)
 * Hi [@michaing](https://wordpress.org/support/users/michaing/), thanks for your
   detailed message.
 * We at Wordfence don’t maintain the WordPress forums to rectify any reasons why
   a message may have been flagged as spam. I expect the WordPress.org moderators
   have already reviewed this topic and correctly decided that it isn’t.
 * PHP 8.1 is not officially released until November 25th 2021 so we wouldn’t recommend
   running it on a production site for at least a few months. WordPress core still
   has some outstanding issues on PHP 8.1 as well, so you could encounter problems
   in another area of your site too. There will be a compatibility release of Wordfence,
   including a fix for the issue you’ve spotted here, coming up shortly although
   we can’t commit to exact dates or timescales here on the forum.
 * Thanks,
 * Peter.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15070919)
 * Moderator note:
 * We find that Akismet generally flags rapid edits as potential spam, so humans
   need to review:
 *     ```
       This topic was modified 3 days, 7 hours ago by Micha. Reason: Found further info about how getJSON is intended to be used
       This topic was modified 3 days, 7 hours ago by Micha.
       This topic was modified 3 days, 7 hours ago by Micha.
       ```
   
 *  Thread Starter [Micha](https://wordpress.org/support/users/michaing/)
 * (@michaing)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15070967)
 * I’ll review more carefully before posting next time. Sorry for the extra moderation
   work.
 * Also WordPress itself does not officially support PHP8.1 but is working on it
   for WordPress v5.9. But as it doesn’t hurt to have PHP8.1 related issues collected
   or even resolved before its official release, I didn’t hesitate to report it.
   If there is a better place to do so, instead of a ticket here, please redirect
   me.
 * Best regards,
 * Micha
 *  Plugin Support [wfpeter](https://wordpress.org/support/users/wfpeter/)
 * (@wfpeter)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15077066)
 * Hi [@michaing](https://wordpress.org/support/users/michaing/),
 * We certainly appreciate feedback from the community to help resolve issues especially
   when we’re working on a compatibility release such as this. Your observervation
   is totally correct and is on our list of fixes to make. I just wanted to be thorough
   with my response regarding PHP 8.1 as others will often reference tickets on 
   the forums.
 * You can always address issues like this and product suggestions directly to **
   feedback @ wordfence . com** so can be seen immediately by the correct team.
 * Thanks,
 * Peter.
 *  Thread Starter [Micha](https://wordpress.org/support/users/michaing/)
 * (@michaing)
 * [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15077167)
 * Great. I’ll send an email then, when facing PHP8.1 related issues, until it is
   supported officially by WordPress and by Wordfence. Makes sense to not spam a
   support/bug tracker with unsupported setup/beta testing.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘TypeError: json_decode() in lib/wfConfig.php(545)’ is closed to new replies.

 * ![](https://ps.w.org/wordfence/assets/icon.svg?rev=2070865)
 * [Wordfence Security - Firewall, Malware Scan, and Login Security](https://wordpress.org/plugins/wordfence/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordfence/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordfence/)
 * [Active Topics](https://wordpress.org/support/plugin/wordfence/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordfence/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordfence/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [Micha](https://wordpress.org/support/users/michaing/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/typeerror-json_decode-in-lib-wfconfig-php545/#post-15077167)
 * Status: resolved