# 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 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? 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. Oct 25 '16 at 14:01
• Got it, with stress on object ;) 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" Feb 2 '17 at 15:05

# 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 :( Jun 19 '17 at 22:50
• @CalculatorFeline hu? 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 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. 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. 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. Oct 26 '16 at 16:48
• @manatwork Yes, exactly. Oct 26 '16 at 17:07

# IBM/Lotus Notes @Formula, 24 23 bytes

Computed value in a Notes field.

"{\"\":"+@Text(@Pi)+"}"


Outputs:

{"":3.14159265358979}


Nothing clever - just uses the shortest possible function that outputs a number then converts it to text for display.

• Useless? Why? You can still refer that value by its key and use it: pastebin.com/RqbbUBEt Oct 25 '16 at 10:33
• I guess so. If it is considered acceptable then I'll edit my answer accordingly. Oct 25 '16 at 10:35

# Japt, 11 bytes

There are a multitude of 11-byte programs:

\{"{O}":1}  // {"[object Object]":1}
\{"{M}":1}  // {"[object Math]":1}
\{"{@}":1}  // {"function (X,Y,Z){return }":1}
\{"{_}":1}  // {"function (Z){return Z}":1}
\{"{Ð}":1}  // {"Tue Oct 25 2016 12:15:24 GMT-0400 (Eastern Standard Time)":1}
\{"":{+Ð}}  // {"":1477412000095}


The last two use the Date object; thus, they are non-constant, but always output more than 15 bytes. Explanation:

\{"   ":1} // Take this string,
{O}      // inserting variable O here.
// O is an Object, which stringifies to "[object Object]".
// Implicitly output.


Test it online!

More interesting 12-byte version:

\{":{L²}}²


Prints {":10000}{":10000}. Explanation:

\{":    }   // Take this string,
{L²}     // inserting 100 squared (10000) here,
// (this yields {":10000})
²  // and double.
// Implicitly output.


Test it online!

## Common Lisp, 24 bytes

(format t"{~S:~f}""p"pi)


Prints the following to standard output (23 characters long):

{"p":3.141592653589793}


This is a simple string format which uses the predefined constant PI.

# q, 14 bytes

Prints memory usage information about the current process

-1@.j.j .Q.w;


Sample output:

q)-1@.j.j .Q.w;
{"used":127392,"heap":67108864,"peak":67108864,"wmax":0,"mmap":0,"mphy":16735457280,"syms":585,"symw":18925}

• Could you provide sample output? Oct 25 '16 at 14:09
• sure, updated post Oct 25 '16 at 17:48

# CoffeeScript, 18 16 bytes

Saved 2 bytes thanks to @Caffeinated.tech

->'{"":'+1/3+'}'


Outputs {"":0.3333333333333333}. Sadly, because of the required double-quotes, string interpolation is a byte longer:

->"{\"\":#{1/3}}"

• You can use the fact that float division is default in Coffee, which let's us use 1/3 instead of undefined to give the length of the required output. I got it to 16 chars: ->'{"":'+1/3+'}' Oct 26 '16 at 12:36
• @Caffeinated.tech The main reason I didn't think of that was that I didn't realize that Coffee's functions could be arg-less, so thanks for teaching me that :) Oct 26 '16 at 13:18

## Charcoal, 7 bytes

{"⁹":9}


Try it online!

Runs of printable ASCII characters in Charcoal form literal strings, and expressions lacking any explicit command are printed. So {" and ":9} are just output verbatim. ⁹, however, is an integer literal, and when you print an integer, you get an ASCII-art line that many characters long. The character used for horizonal lines is the hyphen, so the result is:

{"---------":9}


Conveniently, this is exactly 15 characters.

TSQL(2016 only), 50 BYTES

SELECT*FROM(VALUES(GETDATE()))AS A(a)FOR JSON PATH

• You don't require the AS  for the alias and NEWID instead of GETDATE will save a couple as well. Jun 20 '17 at 1:36

# Java 8 (Full Program), 125 Bytes 123 Bytes 116 Bytes

Yes, I know there are shorter ways in Java, as posted above. I just wanted to approach it from a looping perspective.

Thanks to ais523 for saving 2 bytes.
Thanks to Manatwork for saving 7 bytes.

interface C{static void main(String[]a){for(int i=0;i++<9;)System.out.print(i<2?"{":"\""+i+"\":"+i+(i>8?"}":","));}}


Ungolfed

interface C{
static void main(String[]a){
//Loop from 0-8, add one to i at start of loop instead of end though
for(int i=0;i++<9;)
//If it is a start case simply print { otherwise print "i":i
//If it is an end case also print } otherwise also print :
System.out.print(i<2?"{":'"'+i+"\":"+i+(i>8?"}":","));
}
}

• Assuming you want to keep with this algorithm (which is almost certainly not the best for optimizing your score), you can nonetheless make the program a bit shorter by using < and > comparisons rather than ==.
– user62131
Jun 19 '17 at 10:19
• Good idea, I'll update the code. I don't know why but I really wanted to make a loop. Jun 19 '17 at 10:20
• You have an accidental  left at the end of your golfed code. While removing it, you could also remove the unnecessary {} around for's only statement and change "\""'"'. Jun 19 '17 at 10:26
• There would be one more way to reduce it: i<2?"{":"\""+i+"\":"+i+(i>8?"}":","). With this the "1":1, part vanishes from the output, though it remains long enough to be valid. Jun 19 '17 at 10:35
• Welcome to PPCG! Jun 19 '17 at 10:36

# Turtlèd, 15 bytes

'{r'"10:'"r":3}


### Try it online

outputs {" ":3}

## Explanation

'{               write {
r              move right, off {
'"            write "
10          put 10 in register
:         move right that many characters (puts spaces in)
'"r       write ", move right of that character
":3}   write :3}


# 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

• Your program should take no input. Oct 25 '16 at 17:02
• @NathanMerrill fixed, the only cool part to my answer is the Grails part anyway. Oct 25 '16 at 17:05

# Myth, 28 26 bytes

{"a":"{\":3141}","_":"aa"}


Saved 2 bytes by adapting the solution given by the /// answer.

Myth is a language similar to Thue, contained in a valid JSON object. How appropriate! Here, _ is the initial state, and replaces a with "****". Output:

{":3141}{":3141}


For clarity, I added some spaces:

{
":3141}{"  :  3141
}


## Previous solutions

28 bytes: {"a":"\"****\"","_":"{a:a}"}. Outputs: {"****":"****"}

## Running

I found the interpreter here:

function(m,y,t,h){m=JSON.parse(m);for(y=m._;h=1;){for(t in m)if(t!="_"&&~y.indexOf(t)){y=y.replace(t,m[t]);h=0;break}if(h)break}return y}


Test it out right here:

function myth(m,y,t,h){m=JSON.parse(m);for(y=m._;h=1;){for(t in m)if(t!="_"&&~y.indexOf(t)){y=y.replace(t,m[t]);h=0;break}if(h)break}return y}
b.onclick=function(){o.innerHTML="";o.appendChild(document.createTextNode(myth(q.value)));}
textarea {
width: 90%;
}
*{font-family:Consolas,monospace;}
<textarea id=q>{"a":"\"****\"","_":"{a:a}"}</textarea>
<br>
<button id=b>execute myth code</button>
<br>
<textarea id=o disabled>output</textarea>

Addict is a Turing tarpit where the only control flow is user-defined commands.

a A
i 1
i 1
d
a B
A 1
A 1
d
a C
B 1
B 1
d
a D
C 1
C 1
d
D b
D b
D b
D b
D b
D b
D b
C b
B b
d b
D q
D q
A q
c b
c q
c q
D q
C q
c q
n b
n q
n b
n q
A b
c b


This outputs {"":1235812358}. Try it in the online interpreter!

## How it works

To golf answer space, I'm going to refer you to the sections Primer on Addict and Act I on "Hello, World!" in Addict. If you already know how that works, feel free to skip this part.

## Act II

The rest of the program is devoted to outputting a valid JSON object in as few bytes as possible. In order to minimize the code, we can use the variables that are already set to output a number with the n command. The first step is then to set three variables to the two chars we need at first:

• b to 123, the char code of {
• q to 34, the char code of "

After these have been set, we output {"" one char at a time, then increment q by 24, resulting in 58, the charcode of :. We output that, then output the values of b and q twice, printing 1235812358. The last step is to increment b by 2 to change it to }, and then output it to finish.

If you can find any way to golf this program, please let me know!

# Crystal, 23 bytes

puts %Q({"#{"a"*9}":0})


You can also avoid using %Q (and keep the same character count):

puts "{\"#{"a"*9}\":0}"


The above return:

{"aaaaaaaaa":0}


Which has exactly 15 characters.

# Actually, 10 bytes

'}Qè;':@'{


Try it online!

Explanation:

'}Qè;':@'{
'}          push "}"
Q         push this program's source code
è        call Python's repr function (essentially just wraps the string in double-quotes)
;       duplicate
':@    push ":", swap with one copy of double-quoted source code
'{  push "{"
implicitly print each stack item, separated by newlines, starting with the top


Output:

{
"'}Qè;':@'{"
:
"'}Qè;':@'{"
}


# Javascript, 14 bytes

'{"":'+1e9+'}'


Gives:

{"":1000000000}


I know that this doesn't actually print out anything, it merely returns. But so do all other Javascript solutions here.

• You need to either define a function, or a full program (with printing). Oct 26 '16 at 16:40
• @NathanMerrill allmost all other javascript/ecmascript solutions do no printing. The rule about function or program was added later.
– nl-x
Oct 31 '16 at 8:46
• I guess it's a REPL?
– l4m2
Apr 20 '18 at 12:46

_=>{"":${9e9}}  It will run in most modern ECMAScript environments (eg. Firefox, Chrome, MS Edge, Opera, Node…). JavaScript, 17 bytes _=>'{"'+{}+'":0}'  outputs {"[object Object]":0} passes validator at jslint This works because {} will implicitly be cast to string with the + concatenation, and calling toString on an object returns "[object Object]". Actionscript 3, 27 bytes trace(JSON.stringify(int)); outputs {"MAX_VALUE":2147483647,"length":1,"MIN_VALUE":-2147483648,"prototype":{}} C#, 39 bytes string j(){return"{\""+1.0/0+"\":42}";}  In C#, division of 0 with a double (hence the inclusion of .0), will result in Infinity. Output: {"Infinity":42} • Cool. Do you need the 0 in 1.0, or will 1./0 suffice? Oct 28 '16 at 23:34 • 1./0 is a syntax error in c#, namely "Identifier expected". Nice thought though :) Oct 28 '16 at 23:55 # Python 2, 13 bytes print{"'":.1}  Outputs: {"'": 0.10000000000000001}  Since tenths can't be stored exactly in binary Python outputs a 1 followed by 15 zeros followed by a 1 after the decimal point. Need double quotes around the single quote to not have the double quotes converted to single quotes (thanks to @JonathanAllan's comment to @xnor's answer). • Doesn't seem to work the same way here: pastebin.com/P5vau3WB Oct 31 '16 at 8:59 • @manatwork Works with QPython on my android Oct 31 '16 at 10:52 • @manatwork And Python 2.6.6 but not Python 2.7.1 Oct 31 '16 at 13:03 # Rust, 21 bytes ||"{\"a\":0.1234567}"  String substitution would be too verbose, but at least there's always terse lambdas with implicit returns. With "test code": fn main(){ let f=||"{\"a\":0.1234567}"; println!("{}", f()); }  # Pushy, 12 bytes {"A":1}"  Try it online! This produces the output: {"ABCDEFGHIJKLMNOPQRSTUVWXYZ":1}  Any text wrapped in backticks is a string literal. The A injects the whole uppercase alphabet. Then, the final " command prints it all. # SmileBASIC, 27 bytes ?"{ ?CHR$(34)*2;":
?PI();"}


Printing quotation marks is a huge pain in BASIC. 8 bytes wasted!

### Output:

{
"":
3.14159265}


Exactly 15 characters, without the whitespace.

# 05AB1E, 15 13 bytes

„{"A„":Jû¨'}J


Try it online!

{"abcdefghijklmnopqrstuvwxyz":"zyxwvutsrqponmlkjihgfedcba"}

• Your code outputs single quotes instead of double Feb 2 '17 at 14:25
• @user2428118 fixed at a -2byte cost. JSON with ' is parsable in some languages though. Feb 2 '17 at 14:57
• @MagicOctopusUrn Doubt it. It's probably not actual JSON if single quotes are parsable, maybe you meant dictionaries? Jan 20 at 19:50

## PowerShell, 17 bytes

Slightly unclear on how strict the 'no input' thing is, if it's just no user input or of system input is also disallowed. While my best answer isn't shorter than the other PowerShell answer I think it is novel.

ps|ConvertTo-Json


Gets running processes (default return is an object) and converts that object to a json. Several other two and three letter aliases commands work.

Sample output omitted because it's 34115 lines long and trying to redact my username and computername was a pain.

gl|ConvertTo-Json


Gets your current filesystem location (as an object) and converts that object to a json

gci|ConvertTo-Json


Gets the files in your current path (as an object) and converts that object to a json

You can also take things like inherent type definitions (which are part of the language itself) and pipe them into the conversion function.

[xml]|ConvertTo-Json


Gets the definition of the xml datatype and converts that object to a json

[int]|ConvertTo-Json


Gets the definition of the 32bit integer datatype and converts that object to a json

• So, ps is valid in my book, because you're depending on the fact that there are processes running in the system. gl and gci depend on things that you can't necessarily assume, so are invalid IMO. Jun 20 '17 at 2:30

# Prolog (SWI), 19 bytes

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


Try it online!

# Tcl, 18 bytes

puts \{"[pwd]"\:4}
`

Try it online!