# Print some JSON

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!

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

## Python 2, 14 bytes

print{str:1}


Outputs:

{"<type 'str'>": 1}


The backticks get the string representation in Python 2. Usually, this outputs inside creates single quotes, which Python recognizes as delimiting a string, but JSON doesn't. But Sp3000 observes that when stringifying a type, the type description already contains single quotes, which forces the outer quotes to be double quotes.

• @Sp3000 That's beautiful in an awful way. – xnor Oct 25 '16 at 2:04
• And I thought JS was the only language you can truly abuse type casting in... – Downgoat Oct 25 '16 at 3:20
• same approach works for py3 with 20 bytes print({repr(str):1}) – dahrens Oct 25 '16 at 13:32
• @dahrens for Py3: print({"'"*9:9}) for 16 (print{"'"*9:9} is another 14 in Py2) – Jonathan Allan Oct 25 '16 at 16:14

# jq, 6 characters

(3 characters code + 3 characters command-line option.)

env


CW because I am sure this is not the kind of answer you intended to allow.

Sample run:

bash-4.3$jq -n 'env' { "GIT_PS1_SHOWDIRTYSTATE": "1", "TERM": "xterm", "SHELL": "/bin/bash", "GIT_PS1_SHOWUNTRACKEDFILES": "1", "XTERM_LOCALE": "en_US.UTF-8", "XTERM_VERSION": "XTerm(322)", "GIT_PS1_SHOWSTASHSTATE": "1", "GIT_PS1_SHOWUPSTREAM": "auto", "_": "/usr/bin/jq" }  (Output obviously shortened.) • This is definitely a valid submission (and no need to CW) – Nathan Merrill Oct 25 '16 at 12:30 • – Sanchises Oct 25 '16 at 12:40 • This counts as offloading the solution to a built in, which is almost a forbidden loophole. Keyword: almost – John Dvorak Oct 25 '16 at 15:56 • @JanDvorak It is not always a loophole, because there are cases where it is interesting to see a built-in used. This is one of them. – Fengyang Wang Oct 26 '16 at 2:43 • I won't do it against your explicit wishes, but I agree that this should be unwikied. Also, current consensus is that interpreter flags have to count the difference between invocation with and without the flag, so -n and a space account for three extra bytes. – Dennis Oct 26 '16 at 22:01 # Jelly, 11 bytes “Ɠɼ'ẸẠḌȷżÑ»  Try it online! ### Output {"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}  • Not a rickroll. – Dennis Oct 25 '16 at 2:26 • It has 6 consonants in a row twice (pwllgw and bwllll). What even is this? – Steven H. Oct 25 '16 at 2:46 • @ETHproductions Sure, but I need at least 9 letters to comply with the limit. All words with 6+ letters are in the long dictionary, so it doesn't really matter which one you pick. – Dennis Oct 25 '16 at 19:39 • – TRiG Oct 26 '16 at 12:09 • Wait, Jelly has a built-in for this? – Buffer Over Read Oct 26 '16 at 23:02 # Notepad, 7 keystrokes If you have a Windows computer with the Notepad program, type this: {"F5":0} On my Windows 7 computer, at least, this gives you something like: {"3:42 PM 10/25/2016":0}  • @cat It's a program, not a programming language, but then again, I believe Vim is the same. – ETHproductions Oct 26 '16 at 1:36 • Well, Vim is a programming "language", both in that it fulfills PPCG rules (not Turing completeness) but also in Turing completeness (at least, I'm pretty sure) – cat Oct 26 '16 at 1:38 • @cat I see. I'm not sure if Notepad is Turing-complete. I doubt it, but perhaps; after all, /// has been proven so, and Notepad can pretty well recreate its single feature. – ETHproductions Oct 26 '16 at 1:41 • Vim is different from Notepad - you can save a script and run it within the editor. There is no such feature in Notepad. Thus, the features in Notepad (rudimentary search-and-replace, copying, and pasting) that allow it to be TC require navigating dialogs each time - which means more keystrokes. – Mego Oct 26 '16 at 5:19 • @cat Yeah, sorry, I meant it has been allowed since our discussion. – ETHproductions Nov 22 '16 at 22:51 # Java (JDK 10), 20 bytes v->"{\"\":"+1/.3+"}"  Try it online! ## Output {"":3.3333333333333335}  • Java is the last language I would expect to overload + to String.concat >:^( – cat Oct 26 '16 at 1:23 • @cat Yes, it's actually the only overload that exists. The thing is it doesn't even overload String.concat! If you check the bytecode, this is what Java compiles into: ()->new StringBuilder("{\"\":").append(1/.3).append("}").toString(). Also, don't worry, this is still the longest answer on this page, bar the Brainfuck one and the Java 7 one. So Java holds its rank ;) – Olivier Grégoire Oct 26 '16 at 8:19 # PHP, 14 13 bytes {"":<?=M_E?>}  Prints a nice mathsy object that one could almost pretend is useful: {"":2.718281828459}  Uses the fact that php prints anything outside the tags verbatim to save on some quotation marks, M_E was the shortest long enough constant I could find. edit: saved one byte thanks to Lynn. Sadly it's no longer a 'nice' mathsy object. • "" is a valid JSON key. – Lynn Oct 25 '16 at 13:39 # JavaScript, 17 15 bytes Thanks to @Neil for this one. Call with no input. _=>{"${_}":0}


Outputs {"undefined":0}

### Old version, 16 bytes

Thanks to @kamoroso94 for -1 on this version

_=>{"":${9e9}}  Outputs {"":9000000000} • You could turn this into an arrow function to remove 4 bytes. – DanTheMan Oct 25 '16 at 2:00 • Can you have an empty key? (e.g. remove a) – Conor O'Brien Oct 25 '16 at 2:08 • _=>{"a":${_}} results in {"a":undefined}, which is exactly 15 characters. Noted that you don't use any input when calling this function – Bassdrop Cumberwubwubwub Oct 25 '16 at 10:48
• @BassdropCumberwubwubwub Coincidentally, your code is also 15 characters. I'm not sure that undefined is a valid value in JSON, but that's readily fixed by making it the property name and using a zero value: _=>{"${_}":0}. – Neil Oct 25 '16 at 12:03 • Remove the a to make the key the empty string, a valid key in JSON. 1 less byte. – kamoroso94 Oct 25 '16 at 13:25 ## Brainfuck, 50 bytes +[+<---[>]>+<<+]>>+.>>>--.<+++<[->.<]>>.<+.-.<<++.  Outputs {"999999999999999999999999999999999999999999999999999999999999999999999999999999999":9}. Assumes an interpreter that has 8-bit cells and is unbounded on the left. Try it online! # Pyth - 5 bytes Prints {"'abcdefghijklmnopqrstuvwxyz'": 10}. XHGT  • JSON only allows double quotes unfortunetly – Downgoat Oct 25 '16 at 3:21 • @Downgoat ah, fixing for one byte. – Maltysen Oct 25 '16 at 3:22 • @Downgoat fixed. – Maltysen Oct 25 '16 at 3:22 # Jolf, 9 bytes "{¦q:¦q}"  Outputs: {"{¦q:¦q}":"{¦q:¦q}"}. Try it here! "{¦q:¦q}" "{ : }" raw string ¦q insert the source code here ¦q and here  # Pyth, 7 bytes .d],G0  Creates a dictionary containing a single key "'abcdefghijklmnopqrstuvwxyz'" and value 0: .d Dictionary from: ] The single-element list containing: , The two-element list containing: G The representation of the alphabet (the key) 0 and 0 (the value) Implicitly print the stringification of this.  ## Batch, 16 bytes Prints {"Windows_NT":0}. @echo {"%OS%":0}  • Could you please add the (example) output? – grooveplex Oct 26 '16 at 21:15 # ///, 15 14 characters /a/{":1234}/aa  (At least the output is 1 2 characters longer than the code.) Try it online! Thanks to: • ETHproductions for reusing the object delimiters as part of key (-1 character) Sample run: bash-4.3$ slashes.pl <<< '/a/{":1234}/aa'
{":1234}{":1234}


Just to make it more readable:

bash-4.3$slashes.pl <<< '/a/{":1234}/aa' | jq '' { ":1234}{": 1234 }  • That's a clever way to save bytes :-) – ETHproductions Oct 25 '16 at 13:49 • You can save another one with /a/{":1234}/aa (outputs {":1234}{":1234}) – ETHproductions Oct 25 '16 at 14:41 • Amazing, @ETHproductions. Thanks. – manatwork Oct 25 '16 at 15:12 # R, 19 bytes cat('{"',lh,'":1}')  Becomes a bit longer because the need to escape quotes \". Furthermore, lh is one of the built-in datasets in R and is (to my knowledge) the object with the shortest name that contains the 9 characters needed to fill the length of the key. (edit: turns out pi does the trick as well with the standard option and I was beaten by @JDL who was clever enough to escape using single quotes rather than the extra backslashes) The description of lh in the R-documentation is: A regular time series giving the luteinizing hormone in blood samples at 10 mins intervals from a human female, 48 samples. which is a rather unexpected name of a key, but hey, it works and produces the output: {" 2.4 2.4 2.4 2.2 2.1 1.5 2.3 2.3 2.5 2 1.9 1.7 2.2 1.8 3.2 3.2 2.7 2.2 2.2 1.9 1.9 1.8 2.7 3 2.3 2 2 2.9 2.9 2.7 2.7 2.3 2.6 2.4 1.8 1.7 1.5 1.4 2.1 3.3 3.5 3.5 3.1 2.6 2.1 3.4 3 2.9 ":1}  The answer can be compared to just padding the key with "random" letters to make the output at least 15 characters (24 bytes): cat("{\"HeloWorld\":1}")  • You can avoid the escaping backslashes by using single quotes in the R expression: cat('{"',lh,'":1}') as I did above (though I used pi instead of lh). In my search for two-letter variables I came across the function el which I never knew existed. Could be useful in future... – JDL Oct 25 '16 at 11:47 ## PowerShell 2220 14 Bytes '{"":'+1tb+'}'  Output {"":1099511627776}  Using the constant defined for 1TB in bytes to reach the character limit and the value of a static integer to make for valid json. Thanks to TimmyD for reducing the characters by 5 by removing some redundancy. ### Earlier Post 40 Bytes "{$((1..9|%{'"{0}":{0}'-f$_})-join",")}"  Output {"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}  Takes a integer array and creates a key-value pair for each. Join with commas and wrap with a set of curly braces. # 05AB1E, 9 bytes Unfortunately, 05AB1E doesn't have a dictionary object so we have to construct our own. ’{"èÖ":7}  Try it online! Output {"dictionaries":7}  ## Retina, 11 bytes  {"9$*R":1}


### Output

{"RRRRRRRRR":1}


Note: the leading newline is significant as nothing is replaced with the resultant output, I've used a non-breaking space to illustrate this!

Try it online!

# V, 9 bytes

i{"¹*":0}


Try it online!

Very straightforward. Enters insert mode, enters the following text:

{"*********":0}


The reason this is so short is because ¹ repeats the following character 9 times.

• I was expecting the 0 byte one :P – Maltysen Oct 25 '16 at 3:23
• @maltysen I did post it. I deleted it because it used single quotes instead of double... :( – DJMcMayhem Oct 25 '16 at 3:32

# JavaScript (ES6) + jQuery, 15 bytes

Because jQuery.

_=>{"${$}":0}


Outputs {"function (a,b){return new n.fn.init(a,b)}":0} when called. Try it here:

f=_=>{"${$}":0}
alert(f())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

• The assignment is to output something. without the alert() you are not outputting anything – nl-x Oct 26 '16 at 16:01
• @nl-x The OP has edited to clarify that functions that return the string are allowed. – ETHproductions Oct 26 '16 at 17:08

# Dyalog APL, 9 bytes

⎕JSON⎕DMX


Try it online!

In a clean workspace on my PC the result is

{"Category":"","DM":[],"EM":"","EN":0,"ENX":0,"HelpURL":"","InternalLocation":["",0],"Message":"","OSError":[0,0,""],"Vendor":""}

⎕JSON convert to JSON

⎕DMX the (universally available) Diagnostic Message Extended object

# brainfuck, 83 bytes

--[-->+++++<]>.+[---->+<]>+++.>-[>+<-----]>.........<<.[----->+<]>.>.>--[-->+++<]>.


Outputs {"333333333":3}

There is likely another shorter solution, but I have not yet found it.

Explanation:

--[-->+++++<]>. {
+[---->+<]>+++. "
>-[>+<-----]>.  3
........
<<.             "
[----->+<]>.    :
>.              3
>--[-->+++<]>.  }


Try it online

### PHP, 19 bytes

<?='{"'.(9**9).'":1}';


Output: {"387420489":1}

https://eval.in/665889

Thanks to manatwork for the tips!

• Your output is 16 characters long, while the requirement is 15. So why not remove that “H”? – manatwork Oct 25 '16 at 8:33
• BTW, since PHP 5.6 there is a ** operator: pow(9,9)(9**9). – manatwork Oct 25 '16 at 8:48
• 15 chars (not really PHP): {"<?=9**9?>":1} – Loovjo Oct 25 '16 at 11:06

# Java 7, 36 bytes

String c(){return"{\"a\":"+1e6+"}";}


# Java 8, 21 bytes

()->"{\"a\":"+1e6+"}"


Ungolfed & test code:

Try it here.

class M{
static String c(){
return "{\"a\":" + 1e6 + "}";
}

public static void main(String[] a){
System.out.println(c());
}
}


Output (length 15):

{"a":1000000.0}

• Second solution gives an error – Numberknot Oct 25 '16 at 8:28
• "length varies between 15 and 16 depending on the hash". Hashes can technically have a length as small as 1 (see System.identityHashCode(Object)). – Olivier Grégoire Oct 25 '16 at 9:19
• Also, you can golf 1 byte by using "" as key and 1e7 as value. "" is a valid key when tried in the validator. – Olivier Grégoire Oct 25 '16 at 9:25
• @OlivierGrégoire Ok, I'll remove the this code. As for the "" with 1e7, that won't work unfortunately. 1e6 outputs 1000000.0, but 1e7 outputs 1.0E7 instead. – Kevin Cruijssen Oct 25 '16 at 9:30
• Oh, my mistake, I didn't check. – Olivier Grégoire Oct 25 '16 at 9:31

# R, 19 bytes

This works in British English locale; it may require +2 bytes in others. (Edit: it probably doesn't --- see comments.)

cat('{"',pi,'":1}')


I was hoping for something clever (perhaps plucking a line of code out of a pre-existing function like q) but couldn't find anything. The result:

{" 3.141593 ":1}


Note that you don't have to escape double quotes in R if you use single quotes to quote the string (and vice-versa). This behaviour is locale-dependent though. I would expect it to work in a US English locale as well though.

This also requires that your default digits option is at least six (which is the factory-fresh default) and that scipen is at least -digits (the factory-fresh default is zero).

• Sorry, what? R's grammar changes with locale? – cat Oct 26 '16 at 1:27
• Yes, which characters need escaping depends on options(quote) which can be specified by the user, but the default is, as far as I know, locale-dependent. – JDL Oct 26 '16 at 7:23
• @cat I think that’s a misunderstanding. The existence of options('quote') isn’t documented, changing it has no discernible effect, and though I’ve come across a great deal of shenanigans in R I doubt that runtime options would change the way it’s parsed. It may change the output of course — but not in the code in this answer. – Konrad Rudolph Oct 26 '16 at 11:33
• @Konrad, you might be right. I think I was thinking of "useFancyQuotes" which only affects quote, squote etc. – JDL Oct 26 '16 at 11:37

## Ruby, 19 bytes

puts'{"1":'+9**9+?}


Output:

{"1":387420489}

• @NathanMerrill Fixed – dkudriavtsev Oct 25 '16 at 2:11
• Can you show what it outputs – curiousdannii Oct 25 '16 at 3:11
• Can't you save a byte by removing the space after puts? – Oliver Ni Oct 25 '16 at 3:49
• I think that ?1*9 is still long enough. – Lee W Oct 25 '16 at 17:29
• @curiousdannii Done – dkudriavtsev Oct 25 '16 at 18:57

# Element, 18 bytes

\{\"a\"\:9 9^\}


Try it online! Outputs {"a":387420489}

This is only three bytes shorter than the naive solution. The first half of the output is hard-coded (too many escape characters to make any other approach feasible), while the value is calculated as 9^9 to make a number long enough.

# Perl 5, 16 15 bytes

Uses the unix timestamp of the moment the program was started as the content of a one-element object. It gives valid output if you run it later than 10:46:39 on 3rd of March 1973. But since we can't go back in time that seems legit.

say"{\"$^T\":1}"  Uses the FORMAT_TOP_HANDLE variable $^ which defaults to STDOUT_TOP.

say"{\"$^\":1}";  Run with -E flag at no additional cost. perl -E 'say"{\"$^\":1}";'


Outputs is 16 bytes long.

{"STDOUT_TOP":1}

• RIP time dependent answer :( – CalculatorFeline Jun 19 '17 at 22:50
• @CalculatorFeline hu? – simbabque Jun 19 '17 at 23:15

# Cheddar, 17 14 bytes

Saved 3 bytes thanks to @ConorO'Brien

->'{":1234}'*2


An anonymous function that returns {":1234}{":1234}, which is a valid JSON object:

{
":1234}{": 1234
}


Try it online!

# Windows batch, 10 bytes

{"%OS%":5}


The environment variable OS contains the string Windows_NT (On all Windows operating systems since 2000, according to this question on Stack Overflow)

• @ETHproductions Oops – penalosa Oct 25 '16 at 20:15
• Is this actually outputting anything? Neil's Batch answer certainly does, but can't remember about any implicit batch output. – manatwork Oct 26 '16 at 9:26
• @manatwork Yes it does, since echo is turned on, the current command is echoed, evaluating the OS variable in the process. – penalosa Oct 26 '16 at 16:39
• Oh. So actually it tries to execute that {"%OS%":5} as it would be a command and you benefit of the elementary tracing feature? That's tricky. – manatwork Oct 26 '16 at 16:48
• @manatwork Yes, exactly. – penalosa Oct 26 '16 at 17:07

# HQ9+, 15 bytes

{"Quineland":0}


Outputs itself. I thought an 8-byte answer would be possible, like so:

{":11QQ}


This outputs {":11QQ}{":11QQ}, which is almost valid JSON, but 11QQ is not a valid value.

HQ9+ is not a valid programming language by PPCG standards, but the OP has allowed non-programming languages.

• This absolutely is not valid. All submissions must be in a valid programming language. – Mego Oct 26 '16 at 5:23
• This is mostly kolmo complexity (mostly, because if it outputs something different it still counts), so I think this could be valid – Destructible Lemon Oct 26 '16 at 5:34
• @DestructibleWatermelon Using a non-programming language is a standard loophole. – Mego Oct 26 '16 at 5:44
• @Mego OP has explicitly allowed non-programming languages now – ETHproductions Oct 27 '16 at 1:08