83
\$\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\$
7
  • 1
    \$\begingroup\$ I like the variety of answers on this one \$\endgroup\$ Commented Oct 25, 2016 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
    Commented Oct 25, 2016 at 13:01
  • 7
    \$\begingroup\$ @Konijn like I said, it must be a valid JSON object. The object is defined by the curly braces. \$\endgroup\$ Commented Oct 25, 2016 at 14:01
  • 1
    \$\begingroup\$ Got it, with stress on object ;) \$\endgroup\$
    – Konijn
    Commented Oct 25, 2016 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\$ Commented Feb 2, 2017 at 15:05

84 Answers 84

76
\$\begingroup\$

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.

\$\endgroup\$
6
  • 23
    \$\begingroup\$ @Sp3000 That's beautiful in an awful way. \$\endgroup\$
    – xnor
    Commented Oct 25, 2016 at 2:04
  • 8
    \$\begingroup\$ And I thought JS was the only language you can truly abuse type casting in... \$\endgroup\$
    – Downgoat
    Commented Oct 25, 2016 at 3:20
  • \$\begingroup\$ same approach works for py3 with 20 bytes print({repr(str):1}) \$\endgroup\$
    – dahrens
    Commented Oct 25, 2016 at 13:32
  • 1
    \$\begingroup\$ @dahrens for Py3: print({"'"*9:9}) for 16 (print{"'"*9:9} is another 14 in Py2) \$\endgroup\$ Commented Oct 25, 2016 at 16:14
  • 4
    \$\begingroup\$ @pxeger id gives {'<built-in function id>': 1} which isn't valid json \$\endgroup\$ Commented Jan 20, 2021 at 20:50
42
\$\begingroup\$

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.)

\$\endgroup\$
7
  • 8
    \$\begingroup\$ This is definitely a valid submission (and no need to CW) \$\endgroup\$ Commented Oct 25, 2016 at 12:30
  • 5
    \$\begingroup\$ Also, meta.codegolf.stackexchange.com/questions/9688/… \$\endgroup\$
    – Sanchises
    Commented Oct 25, 2016 at 12:40
  • 1
    \$\begingroup\$ This counts as offloading the solution to a built in, which is almost a forbidden loophole. Keyword: almost \$\endgroup\$ Commented Oct 25, 2016 at 15:56
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 26, 2016 at 2:43
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Dennis
    Commented Oct 26, 2016 at 22:01
33
\$\begingroup\$

Jelly, 11 bytes

“Ɠɼ'ẸẠḌȷżÑ»

Try it online!

Output

{"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}
\$\endgroup\$
14
  • 16
    \$\begingroup\$ Not a rickroll. \$\endgroup\$
    – Dennis
    Commented Oct 25, 2016 at 2:26
  • 1
    \$\begingroup\$ It has 6 consonants in a row twice (pwllgw and bwllll). What even is this? \$\endgroup\$
    – Steven H.
    Commented Oct 25, 2016 at 2:46
  • 2
    \$\begingroup\$ @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. \$\endgroup\$
    – Dennis
    Commented Oct 25, 2016 at 19:39
  • 2
    \$\begingroup\$ @Dennis. Also not a rickroll, but a song nonetheless. \$\endgroup\$
    – TRiG
    Commented Oct 26, 2016 at 12:09
  • 9
    \$\begingroup\$ Wait, Jelly has a built-in for this? \$\endgroup\$ Commented Oct 26, 2016 at 23:02
23
\$\begingroup\$

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}
\$\endgroup\$
12
  • 1
    \$\begingroup\$ @cat It's a program, not a programming language, but then again, I believe Vim is the same. \$\endgroup\$ Commented Oct 26, 2016 at 1:36
  • 2
    \$\begingroup\$ 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) \$\endgroup\$
    – cat
    Commented Oct 26, 2016 at 1:38
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 26, 2016 at 1:41
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – user45941
    Commented Oct 26, 2016 at 5:19
  • 1
    \$\begingroup\$ @cat Yeah, sorry, I meant it has been allowed since our discussion. \$\endgroup\$ Commented Nov 22, 2016 at 22:51
17
\$\begingroup\$

Java (JDK 10), 20 bytes

v->"{\"\":"+1/.3+"}"

Try it online!

Output

{"":3.3333333333333335}
\$\endgroup\$
2
  • 7
    \$\begingroup\$ Java is the last language I would expect to overload + to String.concat >:^( \$\endgroup\$
    – cat
    Commented Oct 26, 2016 at 1:23
  • 4
    \$\begingroup\$ @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 ;) \$\endgroup\$ Commented Oct 26, 2016 at 8:19
15
\$\begingroup\$

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}

\$\endgroup\$
13
  • \$\begingroup\$ You could turn this into an arrow function to remove 4 bytes. \$\endgroup\$
    – DanTheMan
    Commented Oct 25, 2016 at 2:00
  • 1
    \$\begingroup\$ Can you have an empty key? (e.g. remove a) \$\endgroup\$ Commented Oct 25, 2016 at 2:08
  • \$\begingroup\$ _=>`{"a":${_}}` results in {"a":undefined}, which is exactly 15 characters. Noted that you don't use any input when calling this function \$\endgroup\$ Commented Oct 25, 2016 at 10:48
  • 1
    \$\begingroup\$ @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}`. \$\endgroup\$
    – Neil
    Commented Oct 25, 2016 at 12:03
  • 3
    \$\begingroup\$ Remove the a to make the key the empty string, a valid key in JSON. 1 less byte. \$\endgroup\$
    – kamoroso94
    Commented Oct 25, 2016 at 13:25
14
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ "" is a valid JSON key. \$\endgroup\$
    – lynn
    Commented Oct 25, 2016 at 13:39
13
\$\begingroup\$

Brainfuck, 50 bytes

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

Outputs {"999999999999999999999999999999999999999999999999999999999999999999999999999999999":9}. Assumes an interpreter that has 8-bit cells and is unbounded on the left. Try it online!

\$\endgroup\$
12
\$\begingroup\$

Pyth - 5 bytes

Prints {"'abcdefghijklmnopqrstuvwxyz'": 10}.

XH`GT

Try it online here.

\$\endgroup\$
3
  • \$\begingroup\$ JSON only allows double quotes unfortunetly \$\endgroup\$
    – Downgoat
    Commented Oct 25, 2016 at 3:21
  • \$\begingroup\$ @Downgoat ah, fixing for one byte. \$\endgroup\$
    – Maltysen
    Commented Oct 25, 2016 at 3:22
  • \$\begingroup\$ @Downgoat fixed. \$\endgroup\$
    – Maltysen
    Commented Oct 25, 2016 at 3:22
11
\$\begingroup\$

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
\$\endgroup\$
10
\$\begingroup\$

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.
\$\endgroup\$
10
\$\begingroup\$

///, 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
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ That's a clever way to save bytes :-) \$\endgroup\$ Commented Oct 25, 2016 at 13:49
  • 2
    \$\begingroup\$ You can save another one with /a/{":1234}/aa (outputs {":1234}{":1234}) \$\endgroup\$ Commented Oct 25, 2016 at 14:41
  • \$\begingroup\$ Amazing, @ETHproductions. Thanks. \$\endgroup\$
    – manatwork
    Commented Oct 25, 2016 at 15:12
9
\$\begingroup\$

Batch, 16 bytes

Prints {"Windows_NT":0}.

@echo {"%OS%":0}
\$\endgroup\$
1
  • \$\begingroup\$ Could you please add the (example) output? \$\endgroup\$
    – grooveplex
    Commented Oct 26, 2016 at 21:15
7
\$\begingroup\$

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}
\$\endgroup\$
7
\$\begingroup\$

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}")
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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... \$\endgroup\$
    – JDL
    Commented Oct 25, 2016 at 11:47
7
\$\begingroup\$

PowerShell 22 20 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.

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

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.

\$\endgroup\$
2
  • \$\begingroup\$ I was expecting the 0 byte one :P \$\endgroup\$
    – Maltysen
    Commented Oct 25, 2016 at 3:23
  • 1
    \$\begingroup\$ @maltysen I did post it. I deleted it because it used single quotes instead of double... :( \$\endgroup\$
    – DJMcMayhem
    Commented Oct 25, 2016 at 3:32
6
\$\begingroup\$

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!

\$\endgroup\$
6
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

Japt -Q, 1 byte

M

Try it online!

The output is {"P":3.141592653589793,"Q":1.618033988749895,"T":6.283185307179586}.

How it works

M is a shorthand for JS's Math object, with one-char aliases to existing functions/constants and some extra functions/constants. The constants shown here are:

  • M.P = Math.PI
  • M.Q = Golden Ratio = (Math.sqrt(5)+1)/2
  • M.T = Math.PI * 2

And the boring part: the -Q flag applies JSON.stringify to the output value. Some of the properties are lost (e.g. Math.E and Math.SQRT2), but we still have the above three values and the result is well over 15 characters.

\$\endgroup\$
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

PHP, 19 bytes

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

Output: {"387420489":1}

https://eval.in/665889

Thanks to manatwork for the tips!

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

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}
\$\endgroup\$
2
  • \$\begingroup\$ RIP time dependent answer :( \$\endgroup\$ Commented Jun 19, 2017 at 22:50
  • \$\begingroup\$ @CalculatorFeline hu? \$\endgroup\$
    – simbabque
    Commented Jun 19, 2017 at 23:15
5
\$\begingroup\$

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}
\$\endgroup\$
6
  • \$\begingroup\$ Second solution gives an error \$\endgroup\$
    – Numberknot
    Commented Oct 25, 2016 at 8:28
  • 1
    \$\begingroup\$ "length varies between 15 and 16 depending on the hash". Hashes can technically have a length as small as 1 (see System.identityHashCode(Object)). \$\endgroup\$ Commented Oct 25, 2016 at 9:19
  • 1
    \$\begingroup\$ Also, you can golf 1 byte by using "" as key and 1e7 as value. "" is a valid key when tried in the validator. \$\endgroup\$ Commented Oct 25, 2016 at 9:25
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 25, 2016 at 9:30
  • 1
    \$\begingroup\$ Oh, my mistake, I didn't check. \$\endgroup\$ Commented Oct 25, 2016 at 9:31
5
\$\begingroup\$

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>

\$\endgroup\$
2
  • 1
    \$\begingroup\$ The assignment is to output something. without the alert() you are not outputting anything \$\endgroup\$
    – nl-x
    Commented Oct 26, 2016 at 16:01
  • 1
    \$\begingroup\$ @nl-x The OP has edited to clarify that functions that return the string are allowed. \$\endgroup\$ Commented Oct 26, 2016 at 17:08
5
\$\begingroup\$

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)

\$\endgroup\$
5
  • \$\begingroup\$ @ETHproductions Oops \$\endgroup\$
    – penalosa
    Commented Oct 25, 2016 at 20:15
  • \$\begingroup\$ Is this actually outputting anything? Neil's Batch answer certainly does, but can't remember about any implicit batch output. \$\endgroup\$
    – manatwork
    Commented Oct 26, 2016 at 9:26
  • \$\begingroup\$ @manatwork Yes it does, since echo is turned on, the current command is echoed, evaluating the OS variable in the process. \$\endgroup\$
    – penalosa
    Commented Oct 26, 2016 at 16:39
  • \$\begingroup\$ 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. \$\endgroup\$
    – manatwork
    Commented Oct 26, 2016 at 16:48
  • \$\begingroup\$ @manatwork Yes, exactly. \$\endgroup\$
    – penalosa
    Commented Oct 26, 2016 at 17:07
5
\$\begingroup\$

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).

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Sorry, what? R's grammar changes with locale? \$\endgroup\$
    – cat
    Commented Oct 26, 2016 at 1:27
  • \$\begingroup\$ 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. \$\endgroup\$
    – JDL
    Commented Oct 26, 2016 at 7:23
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Oct 26, 2016 at 11:33
  • \$\begingroup\$ @Konrad, you might be right. I think I was thinking of "useFancyQuotes" which only affects quote, squote etc. \$\endgroup\$
    – JDL
    Commented Oct 26, 2016 at 11:37
5
\$\begingroup\$

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.

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

Bash, 18 bytes

echo {\"$PATH\":1}

This works on Mac and Linux, unless your $PATH isn't set.

\$\endgroup\$
1
  • \$\begingroup\$ This is genius. +1. And welcome to the site! \$\endgroup\$
    – Riker
    Commented Oct 29, 2016 at 0:23
5
\$\begingroup\$

Ruby, 19 bytes

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

Output:

{"1":387420489}
\$\endgroup\$
7
  • \$\begingroup\$ @NathanMerrill Fixed \$\endgroup\$
    – anna328p
    Commented Oct 25, 2016 at 2:11
  • 1
    \$\begingroup\$ Can you show what it outputs \$\endgroup\$ Commented Oct 25, 2016 at 3:11
  • \$\begingroup\$ Can't you save a byte by removing the space after puts? \$\endgroup\$
    – Oliver Ni
    Commented Oct 25, 2016 at 3:49
  • \$\begingroup\$ I think that ?1*9 is still long enough. \$\endgroup\$
    – Lee W
    Commented Oct 25, 2016 at 17:29
  • \$\begingroup\$ @curiousdannii Done \$\endgroup\$
    – anna328p
    Commented Oct 25, 2016 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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