-2

I am actually confused here as to how this json is invalid. I have a piece of json from a much larger json set:

               ...
               "open_until":{  
                  "date":"2015-10-16 00:00:00",
                  "timezone_type":3,
                  "timezone":"America\/Edmonton"
               },
               "ffba_access_code":"1234",
               "overview_content":" 
Elevator Pitch<\/h4>\r\n 
Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.<\/p>\r\n\r\n 

This is a USD investment with monthly distributions remitted in USD.<\/p>",
               .....

when I put this through the json formatter, I am told that:

" 
    Elevator Pitch<\/h4>\r\n 
    Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.<\/p>\r\n\r\n 

    This is a USD investment with monthly distributions remitted in USD.<\/p>"

is the "offending" peice thats "invalid"

I oull this right from the database in php. Is there something I should do to this particular database field when I pull it out to make it comply?

TheWebs
  • 12,470
  • 30
  • 107
  • 211

4 Answers4

1

You cannot have line breaks in property values (or properties either for that sake).

This example lints just fine:

...
"open_until": {
  "date": "2015-10-16 00:00:00",
  "timezone_type": 3,
  "timezone": "America/Edmonton"
},
"ffba_access_code": "1234",
"overview_content": "Elevator Pitch</h4>\r\n Fedilus Funds gives investors the ability to participate in the growth of the United States un-banked sector by deploying 'automated commerce machines' in high traffic areas. This is a blended investment that distributes monthly principal and interest back to the investor and once the term has ended, a percentage of revenue is distributed continuously. You are purchasing a portfolio of advanced ATM's that offer a wide range of financial services coupled with a strong management team.</p>\r\n\r\n This is a USD investment with monthly distributions remitted in USD.</p>"
...
Hampus
  • 2,769
  • 1
  • 22
  • 38
1

JSON does not allow real line-breaks. You need to replace all the line breaks into \n.

John Svensson
  • 392
  • 1
  • 6
0

The answers above are right about line breaks needing to be escaped. Check out php's built-in json_encode() function.

Also, this answer has some helpful info about line breaks and escaping the backslash: Multiline strings in JSON

Community
  • 1
  • 1
wrydere
  • 668
  • 8
  • 17
-3

As some pointed out wrapping the content that comes out of the database in htmlspecialchars did the trick for fixing the issue.

TheWebs
  • 12,470
  • 30
  • 107
  • 211
  • @VolkerK Um i did it on the contents coming from the database – TheWebs Sep 30 '15 at 21:55
  • 1
    You mean the faulty json as show in the question is already in the database; you pull that from a text/varchar field? In that case: What's putting the invalidly enocded (not-)json in the database? Anyway, [htmlspecialchars()](http://docs.php.net/htmlspecialchars) does nothing to linebreak/feed-characters. The characters "handled" by this function are `&`, `"`, "`", `<` and `>` – VolkerK Sep 30 '15 at 22:01