PHP json_encode() and Javascipt JSON.parse() : I need to get data from server in JSON. The data set is very huge and has multi-level nesting. I use arrays. And some keys inside array are JSON strings (i need to store these strings inside database, in order to create JS objects from those strings later).

    Array(
	'key1'=> 'value1',
	'key2'=> 'string in JSON format', // json_encode('key2_value that may contain russian symbols', JSON_UNESCAPED_UNICODE)
	'key3'=> array(
		'key1'=> array(
			key1=> 'string in JSON format'
		)
	)
)

The nesting of elements may be arbitrary and any element may contain string in JSON format.

I encode this huge array in JSON, using php json_encode($data, JSON_UNESCAPED_UNICODE) function. I use second param because data may contain russian symbols (i need to search some of those strings later). After that i receive data...

1 step:
Decode all array with JSON strings using JS JSON.parse() function.

2 step:
Save some JSON strings in database columns and after create JS objects using JSON.parse().

But some strings may contain disallowed JSON characters, in particular '\r'. And when i try to parse this string using JSON parse, i can get JSON.parse error for now in second step. But in theory it may occur also in first step.


But PHP json_decode works Good! JS JSON.parse works Bad!

Does anyone have any idea and suggestions? (Please don't forget, when i use json_encode in main array, nested json strings that may contain russian symbols also escaped - slashes, "" i.e).