: The problem I have is if I try to parse this response in *php *using : *json_decode()* I get a syntax error because of the '*\n*' s that are in : the response. I could escape the before doing the *json_decode() *or at the : point of submitting to the index but this seems wrong...
I don't really know anything about PHP, but i managed to muddle my way through both of the little experiments below and couldn't reporoduce any error from json_decode when the response contains "\n" (ie: the two byte sequence represnting an escaped newline character) inside of a JSON string, but i do get the expected error if a literal, one byte, newline character is in the string. (something that Solr doesn't do) are you sure when you fetch the data from Solr you aren't pre-parsing it in some what that's evaluating hte "\n" and converting it to a real newline? : I am probably doing something silly and a good nights sleep will reveal : what I am doing wrong ;-) Good luck. ### Experiment #1, locally crated strings, one bogus json hossman@frisbee:~$ php -a Interactive shell php > $valid = '{"id": "newline: (\n)"}'; php > $bogus = "{\"id\": \"newline: (\n)\"}"; php > var_dump($valid); string(23) "{"id": "newline: (\n)"}" php > var_dump($bogus); string(22) "{"id": "newline: ( )"}" php > var_dump(json_decode($valid)); object(stdClass)#1 (1) { ["id"]=> string(12) "newline: ( )" } php > var_dump(json_decode($bogus)); NULL php > var_dump(json_last_error()); int(4) ### Experiment #2, fetching json data from Solr... hossman@frisbee:~$ curl 'http://localhost:8983/solr/collection1/select?q=id:HOSS&wt=json&indent=true&omitHeader=true' { "response":{"numFound":1,"start":0,"docs":[ { "id":"HOSS", "name":"quote: (\") backslash: (\\) backslash-quote: (\\\") newline: (\n) backslash-n: (\\n)", "_version_":1458038130437259264}] }} hossman@frisbee:~$ php -a Interactive shell php > $data = file_get_contents('http://localhost:8983/solr/collection1/select?q=id:HOSS&wt=json&indent=true&omitHeader=true'); php > var_dump($data); string(227) "{ "response":{"numFound":1,"start":0,"docs":[ { "id":"HOSS", "name":"quote: (\") backslash: (\\) backslash-quote: (\\\") newline: (\n) backslash-n: (\\n)", "_version_":1458038130437259264}] }} " php > var_dump(json_decode($data)); object(stdClass)#1 (1) { ["response"]=> object(stdClass)#2 (3) { ["numFound"]=> int(1) ["start"]=> int(0) ["docs"]=> array(1) { [0]=> object(stdClass)#3 (3) { ["id"]=> string(4) "HOSS" ["name"]=> string(78) "quote: (") backslash: (\) backslash-quote: (\") newline: ( ) backslash-n: (\n)" ["_version_"]=> int(1458038130437259264) } } } } -Hoss http://www.lucidworks.com/