Stack Exchange
PHP json_decode of cli output
I try to parse in php the console output and decode from json format but get error = quoted object property name expected
the parser itself is an external library and is written in python:
https://github.com/Blizzard/heroprotocol
$output - contains this string:
json_decode($output) fails
I will be thankfull if somebody can help me to find a solution to make json_decode of this 
{'m_cacheHandles': ['s2ma\x00\x00EU\x1f\x1b"\x8d\xdb\x1fr \\\xbf\xd4D\x05R\x87\x10\x0b\x0f9\x95\x9b\xe8\x16T\x81b\xe4\x08\x1e\xa8U\x11',
                's2ma\x00\x00EU\x1a\xd9L\x12n\xb9\x8aL\x1d\xe7\xb8\xe6\xf8\xaa\xa1S\xdb\xa5+\t\xd3\x82^\x0c\x89\xdb\xc5\x82\x8d\xb7\x0fv',
                's2ma\x00\x00EU\x92\xd8\x17D\xc1D\x1b\xf6(\xedj\xb7\xe9\xd1\x94\x85\xc8`\x91M\x8btZ\x91\xf65\x1f\xf9\xdc\xd4\xe6\xbb',
                's2ma\x00\x00EU\xa1\xe9\xab\xcd?\xd2PS\xc9\x03\xab\x13R\xa6\x85u7(K2\x9d\x08\xb8k+\xe2\xdeI\xc3\xab\x7fC',
                's2ma\x00\x00EU[Q\xb6\xcb+e\x93\xa9\xa1\xb0\xd8y\x10;\xd7J\x9b\x0c\x15=u\xe6\xa2\xcc\x10\xa9N\xd1\xba\xe9\xc6&'],
 'm_campaignIndex': 0,
 'm_defaultDifficulty': 7,
 'm_description': '',
 'm_difficulty': '',
 'm_gameSpeed': 4,
 'm_imageFilePath': '',
 'm_isBlizzardMap': True,
 'm_mapFileName': '',
 'm_miniSave': False,
 'm_modPaths': None,
 'm_playerList': [{'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92,     'm_r': 36},
                   'm_control': 2,
                   'm_handicap': 100,
                   'm_hero': 'Jaina',
                   'm_name': 'Gela',
                   'm_observe': 0,
                   'm_race': ' ',
                   'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 1},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Kerrigan',
               'm_name': 'Breez',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 2},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'L\xc3\xa9oric',
               'm_name': 'Mopsio',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 3},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Tyrande',
               'm_name': 'Blekitny',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 4},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Uther',
               'm_name': 'Kr\xc3\xb3Lu',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 5},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Falstad',
               'm_name': 'Atheroangel',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 6},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Muradin',
               'm_name': 'TankFtw',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 7},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Valla',
               'm_name': 'ZDOON',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 8},
              {'m_color': {'m_a': 255, 'm_b': 255, 'm_g': 92, 'm_r': 36},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Balafr\xc3\xa9',
               'm_name': 'scHwimpi',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 2,
               'm_teamId': 0,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 9},
              {'m_color': {'m_a': 255, 'm_b': 0, 'm_g': 0, 'm_r': 255},
               'm_control': 2,
               'm_handicap': 100,
               'm_hero': 'Thrall',
               'm_name': 'Remmerballer',
               'm_observe': 0,
               'm_race': ' ',
               'm_result': 1,
               'm_teamId': 1,
               'm_toon': {'m_id': ,
                          'm_programId': 'Hero',
                          'm_realm': 1,
                          'm_region': 2},
               'm_workingSetSlotId': 10}],
 'm_restartAsTransitionMap': False,
 'm_thumbnail': {'m_file': 'ReplaysPreviewImage.tga'},
 'm_timeLocalOffset': 36000000000,
 'm_timeUTC': 130983747603980954,
 'm_title': 'Comt\xc3\xa9 du Dragon'}


Where does the data come from? You should fix that instead if possible as it does not generate valid json.

The delimiter for string literals in JSON is ", not a single-quote. So, the output is not valid JSON.

it comes from python library, and I don't want to change vendor library as it updates from month to month

Btw: You already got an answer over here. The mentioned version uses json.dumps(event, encoding="ISO-8859-1") to output the json doc  ...and it will be valid (except that I'm not sure about the choice of ISO-8859-1. UTF-8 (or no such parameter since it's the default) would be better, maybe even necessary as json_decode expects utf-8 encoded data.)

s = json.dumps(event, encoding="utf-8");
but get error
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8d in position 11: invalid start byte

JSONLint says that this is not valid JSON-code
JSON does not allow strings to be delimited with single quotes ', you have to use double quotes "
You could try replacing
$output = str_replace('"', '\\"', $output); //this is to escape existing double-quotes
    //which would otherwise break the JSON-string
$output = str_replace("'", '"', $output);

but the right solution would be to fix the library to produce valid JSON
Note: my replacement-fix won't work if there is any escaped single quote in your data.
