-1

I want to return a number and a new line

{ data : "3
"}

But every time, I try to do this it is considered invalid

enter image description here

Update

My parser tool tries to do things with Newlines. Here is the complete screenshot:

enter image description here

** Update 2**

This is with jsonlint.com

enter image description here

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • The error in the screenshot, if you read it carefully, is nothing to do with the newline...it's talking about "position 2" (i.e. the second character of the JSON) and the `d` character (which is of course the second one). Property names in JSON must have double quotes around them. So `{ "data":`...etc – ADyson Apr 22 '19 at 17:36

2 Answers2

2

The problem is that data is not a valid key (check https://www.json.org/ or Do the JSON keys have to be surrounded by quotes?), you need to use quotes for keys in order to have valid syntax. Also you need to add \n for a new line character:

{ "data": "3\n"}
eol
  • 23,236
  • 5
  • 46
  • 64
-1

I pasted this into the console without an error: { "data" : "3\n"}

Testing one step further:

a = { "data" : "3\n"}
a.data + "hello" // pasted into the console

produced this:

3
hello
Steve Lage
  • 692
  • 6
  • 11
  • 1
    1. Your example has data unambiguously as a string. Strings work OK 2. JSON is a subset of Javascript. It does not allow concatenation like that – James A Mohler Apr 22 '19 at 17:41
  • The question is about JSON, not JavaScript – ADyson Apr 22 '19 at 18:42
  • Right. It should be "data", I should have added quotes. However the questions only asked "I want to return a number and a new line". I was just trying to show the use of "\n" to return the number with the newline. – Steve Lage Apr 22 '19 at 18:48