74
2
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:
You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace. Your program should work without any input.
In the interest of clarity, a JSON object starts and ends with curly braces {}
, and contains zero or more key:value pairs separated by commas. The full JSON specification can be found at json.org, and the output of your code must pass this validator.
Therefore, any of the following would not be valid:
4 //Too short, not an object
"really, really long string" //A string, not an object
["an","array","of","values"] //An array is not a JSON object
{"this":4 } //You can't count unessential whitespace
{"1":1,"2":3} //Too short
{"a really long string"} //Not valid JSON, it needs a value
{'single-quoted':3} //JSON requires double-quotes for strings
However, the following would be valid:
{"1":1,"2":2,"3":3,"4":4} //Long enough
{"whitespace ":4} //This whitespace isn't unessential
Non-programming languages are allowed on this challenge. You may return a string from a function, or print it out. This is a code-golf, so answer it with as little code as possible!
1I like the variety of answers on this one – Robert Fraser – 2016-10-25T06:59:21.627
Hmmmm, your definition of JSON is limited. What about code that ouputs valid JSON but does not output curly braces? – Konijn – 2016-10-25T13:01:06.343
4@Konijn like I said, it must be a valid JSON object. The object is defined by the curly braces. – Nathan Merrill – 2016-10-25T14:01:18.727
Got it, with stress on object ;) – Konijn – 2016-10-25T14:06:17.120
What exactly counts as a JSON object, because the JS code
_=>_={100:_}
would return a valid JSON object, just not in a string. Don't forget to putf=
before the code and call likef()
– None – 2017-02-02T14:34:37.1071@Masterzagh Unfortunately, a native JS object doesn't count. "You may return a string from a function, or print it out" – Nathan Merrill – 2017-02-02T15:05:58.387
@NathanMerrill Oh I'm blind, sorry – None – 2017-02-02T15:20:09.847