0

I recently got the Dota 2 item schema by following this guide: http://roshpit.ghost.io/getting-updated-item-schema-for-dota2-despite-app570econ-api-being-down-for-5-months/

Since the file is really large, every time I attempt to verify it with json verifiers such as JSONLint, they stop responding. It looks like proper json, and according to the guide it should be proper json. My problem is that when I use json_decode() in PHP it ends up returning a null or empty.

My guess is that it includes some type of character that is not supported by PHP and thus causing it to return null. I read something regarding UTF8 BOM, but I'm not sure if this is the problem.

Could someone help me identify what's wrong with it?

I have used var_dump() to make sure that the contents of the object that I am trying to decode actually has something.

I have also tried removing the UTF8 BOM characters by using the following php function

function remove_utf8_bom($text)
{
     $bom = pack('H*','EFBBBF');
     $text = preg_replace("/^$bom/", '', $text);
     return $text;
}

And I also tried removing the UTF8 BOM characters using this awk script

awk 'NR==1{sub(/^\xef\xbb\xbf/,"")}{print}' INFILE > OUTFILE

Neither of the UTF8 BOM removals seemed to have any effect.

The following is the json file in question:

Original JSON obtained through guide listed above

1 Answers1

0

I ended up fixing the problem by first finding out what error was being displayed through the use of json_last_error(). It turned out to be 5, which is a UTF8 error. This means that my original thought of the UTF8 formatting was incorrect, but I was not properly fixing it before. In the end, I just ended up using the following to fix it:

json_decode( preg_replace('/[\x00-\x1F\x80-\xFF]/', '', file_get_contents("items_game.json")), true );

This basically just got rid of all of the UTF8 characters that were not supposed to be there when trying to decode the file.