74
\$\begingroup\$

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 , so answer it with as little code as possible!

\$\endgroup\$
  • 1
    \$\begingroup\$ I like the variety of answers on this one \$\endgroup\$ – Robert Fraser Oct 25 '16 at 6:59
  • \$\begingroup\$ Hmmmm, your definition of JSON is limited. What about code that ouputs valid JSON but does not output curly braces? \$\endgroup\$ – Konijn Oct 25 '16 at 13:01
  • 4
    \$\begingroup\$ @Konijn like I said, it must be a valid JSON object. The object is defined by the curly braces. \$\endgroup\$ – Nathan Merrill Oct 25 '16 at 14:01
  • \$\begingroup\$ Got it, with stress on object ;) \$\endgroup\$ – Konijn Oct 25 '16 at 14:06
  • 1
    \$\begingroup\$ @Masterzagh Unfortunately, a native JS object doesn't count. "You may return a string from a function, or print it out" \$\endgroup\$ – Nathan Merrill Feb 2 '17 at 15:05

70 Answers 70

0
\$\begingroup\$

Groovy, 43 Bytes

{groovy.json.JsonOutput.toJson([i:1..9]​)​}

It gives the range 1-9 in JSON stored for i:

{"i":[1,2,3,4,5,6,7,8,9]}

Groovy on Grails, 31 Bytes

def v(){render(params as JSON)}

Controller method, renders the parameters which always include action, controller and a few other meta parameters which results in:

{"action":"v","format":null,"controller":"<Controller Name>"}

When you visit the URL:

http://localhost:8080/<Controller Name>/v
\$\endgroup\$
  • \$\begingroup\$ Your program should take no input. \$\endgroup\$ – Nathan Merrill Oct 25 '16 at 17:02
  • \$\begingroup\$ @NathanMerrill fixed, the only cool part to my answer is the Grails part anyway. \$\endgroup\$ – Magic Octopus Urn Oct 25 '16 at 17:05
0
\$\begingroup\$

Boring answers with literals

Emotinomicon, 32 bytes

😭}1:"        r"{😲⏪⏬⏩

Minecraft, 19 bytes

say {"           ":0}

Or not so boring, but not guaranteed

say @p

And just use the JSON as username

Any texteditor, 15 bytes

Couldn't get it any shorter with copy-pasting

{"123456789":0}

Notepad, 7 bytes

{"F5":1}

Thanks to @ETHProductions

\$\endgroup\$
  • \$\begingroup\$ I forgot about the qoutes and noticed ah I need 11 chars as key. \$\endgroup\$ – Roman Gräf Oct 25 '16 at 19:25
  • \$\begingroup\$ {":1234}<ctrl+a><ctrl+c><right-arrow><ctrl+v> is 15 keystrokes, I suppose, but that's not any shorter, and I'm not sure it would count... \$\endgroup\$ – ETHproductions Oct 25 '16 at 19:33
  • \$\begingroup\$ Yes I tries some copy-pasting but got the same problem you got. :( \$\endgroup\$ – Roman Gräf Oct 25 '16 at 19:34
  • \$\begingroup\$ In Notepad on Windows 7 (perhaps other OSs too), you can do {"<F5>":0} for a grand total of 7 keystrokes (F5 inserts the time/date, e.g 3:37 PM 10/25/2016). Not sure if that counts either... \$\endgroup\$ – ETHproductions Oct 25 '16 at 19:39
  • \$\begingroup\$ Do you know this html tag which looks like keyboard buttons. You know the one that is sometimes uses in Vim answers. I already searched for it but couldn't find it. \$\endgroup\$ – Roman Gräf Oct 25 '16 at 19:43
0
\$\begingroup\$

Pyke, 11 10 8 bytes

~C`0]]1Y

Try it here!

\$\endgroup\$
0
\$\begingroup\$

Ruby (cheap), 22 bytes

->{'{"aaaa":"bbbbb"}'}

Lambda function that returns the String object '{"aaaa":"bbbbb"}'

\$\endgroup\$
  • \$\begingroup\$ "a":"b"*8 would be shorter. \$\endgroup\$ – Magic Octopus Urn Oct 27 '16 at 17:45
  • \$\begingroup\$ @carusocomputing See my other post. \$\endgroup\$ – dkudriavtsev Oct 27 '16 at 19:16
0
\$\begingroup\$

RAGE!!!, 41 bytes

<rant>SCREAM"{\"12345\":54321}"!!!</rant>

Since the interpreter compiler transpiler on the esolangs page converts the code to Python 2 via mere string substitution, escaping double quotes should be okay.

\$\endgroup\$
0
\$\begingroup\$

C#, 76 bytes

using System;public class P{public void Main(){Console.Write("{\"\":"+1/3d+"}");}}

Output:

{"":0.333333333333333}
\$\endgroup\$
  • 1
    \$\begingroup\$ If I'm not mistaken, you can omit the using System; and use instead System.Console.Write(...). This can save you 6 bytes \$\endgroup\$ – auhmaan Oct 28 '16 at 15:30
  • 1
    \$\begingroup\$ @auhmaan: D'uh. You're correct. I had that, but I switched from Math.PI to 1/3d since it's shorter. And because I had to use System for both Console.Write and Math.PI it was shorter to use a using. But now I'm not using Math.PI anymore I can, indeed, get rid of the using system. Thanks for pointing that out! \$\endgroup\$ – RobIII Oct 28 '16 at 16:41
0
\$\begingroup\$

JavaScript

10 chars:

{"":{}+''}

Output:

{"": "[object Object]"}

Well, maybe. If it doesn't like the bare object:

12 chars:

({"":{}+''})

If it doesn't print returned objects the way we need:

This is cleaner (ES2015, 13 chars, borrowing from another solution):

`{"":${9e9}}`

{"": 9000000000}

\$\endgroup\$
  • \$\begingroup\$ “You need to print/return a valid JSON object” – The print/return part is also mandatory. The solutions are expected to be full programs or functions. Your code is a snippet. \$\endgroup\$ – manatwork Oct 31 '16 at 9:01
  • \$\begingroup\$ Hmm I was considering the REPL as a language. \$\endgroup\$ – Steve Bennett Oct 31 '16 at 12:48
0
\$\begingroup\$

Text, 15 Bytes

I'm pretty sure you know that language, and non-programming languages are allowed...

{"hi ":"world"}
\$\endgroup\$
0
\$\begingroup\$

Prolog (SWI), 19 bytes

?-writeq({"":1e7}).

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Vim, 13 bytes

a{"<esc>9aa<esc>a":0}

output:

{"aaaaaaaaa":0}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.