Print some JSON

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

Nathan Merrill

Posted 2016-10-25T01:39:24.747

Reputation: 13 591

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 put f= before the code and call like f() – None – 2017-02-02T14:34:37.107

1@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

Answers

72

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.

xnor

Posted 2016-10-25T01:39:24.747

Reputation: 115 687

20@Sp3000 That's beautiful in an awful way. – xnor – 2016-10-25T02:04:52.957

6And I thought JS was the only language you can truly abuse type casting in... – Downgoat – 2016-10-25T03:20:25.263

same approach works for py3 with 20 bytes print({repr(str):1}) – dahrens – 2016-10-25T13:32:10.903

1@dahrens for Py3: print({"'"*9:9}) for 16 (print{"'"*9:9} is another 14 in Py2) – Jonathan Allan – 2016-10-25T16:14:47.373

37

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

manatwork

Posted 2016-10-25T01:39:24.747

Reputation: 17 865

6This is definitely a valid submission (and no need to CW) – Nathan Merrill – 2016-10-25T12:30:40.363

Certainly valid. But I see no way to make a relevant comparison with any other solution, in this question's context. That is why I feel it should stand aside. – manatwork – 2016-10-25T12:57:54.607

1This counts as offloading the solution to a built in, which is almost a forbidden loophole. Keyword: almost – John Dvorak – 2016-10-25T15:56:30.400

1@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 – 2016-10-26T02:43:52.640

1

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 – 2016-10-26T22:01:40.187

@Dennis, I still feel this is an unfair competitor. But after all, I also feel is unfair to count a space used due to shell syntax, that never reaches the interpreter. Whatever. – manatwork – 2016-10-27T17:15:41.080

31

Jelly, 11 bytes

“Ɠɼ'ẸẠḌȷżÑ»

Try it online!

Output

{"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}

Dennis

Posted 2016-10-25T01:39:24.747

Reputation: 196 637

Is that one word, or multiple? o_o – Conor O'Brien – 2016-10-25T02:26:08.867

13Not a rickroll. – Dennis – 2016-10-25T02:26:59.933

1It has 6 consonants in a row twice (pwllgw and bwllll). What even is this? – Steven H. – 2016-10-25T02:46:22.507

How does this even work... – Oliver Ni – 2016-10-25T03:47:51.677

@Oliver it's a compression of the whole output string (everything between and »). The long Welsh place name is in the dictionary Jelly has. See section 3.1.2 of the tutorial

– Jonathan Allan – 2016-10-25T03:51:30.563

1

@StevenH. "W" is sometimes a vowel in Welsh (for example in crwth)

– Robert Fraser – 2016-10-25T05:22:40.223

1@StevenH. As Robert says, w can be a vowel in Welsh. As for the llll, I believe it is supposed to be parsed as l-ll-l, ll being considered as a single letter. – Fatalize – 2016-10-25T07:15:21.940

Is there really no word with shorter compressed output? – ETHproductions – 2016-10-25T18:08:11.590

2@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 – 2016-10-25T19:39:14.347

1

@Fatalize. Welsh letters are interesting.

– TRiG – 2016-10-26T12:08:55.553

2

@Dennis. Also not a rickroll, but a song nonetheless.

– TRiG – 2016-10-26T12:09:39.233

8Wait, Jelly has a built-in for this? – Buffer Over Read – 2016-10-26T23:02:15.840

@TheBitByte why do we even have that lever?

– Caleb – 2016-10-27T09:52:16.420

Definitely +1 for the craziest label name I have ever seen. I'd hate to have to work with one of your web services. – ElPedro – 2016-10-27T23:39:40.127

19

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}

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

A programming language? – cat – 2016-10-26T01:26:28.370

1@cat It's a program, not a programming language, but then again, I believe Vim is the same. – ETHproductions – 2016-10-26T01:36:45.157

2Well, 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 – 2016-10-26T01:38:21.147

You should ping @DJMCMayhem in chat to learn more, for they are a Vim wizard and I am merely a mortal onlooker.

– cat – 2016-10-26T01:39:51.803

1@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 – 2016-10-26T01:41:22.617

1Vim 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 – 2016-10-26T05:19:00.830

@Mego Yes, I'm aware of that. It doesn't make it any less TC, but it does make it terrible for golfing any non-kolgomorov-complexity challenges... – ETHproductions – 2016-10-26T13:25:38.740

@cat btw, the OP has explicitly allowed non-programming-language entries. – ETHproductions – 2016-11-22T21:26:44.480

@ETHproductions This was never debated but I think that was added after my comment. – cat – 2016-11-22T22:48:33.343

1@cat Yeah, sorry, I meant it has been allowed since our discussion. – ETHproductions – 2016-11-22T22:51:21.023

1Based on memories of keyboard parsing from old DOS days, I suspect this should be counted as 8 bytes. There are two-byte encodings for F5 in many character sets designed for communicating keypresses to an application, and these are commonly seen on DOS (thus indirectly Windows), but I'm not aware of a character set that uses a one-byte encoding. – None – 2017-01-01T07:58:19.293

Is <kbd>"</kbd> 1 byte? – l4m2 – 2018-04-20T12:45:15.190

15

Java (JDK 10), 20 bytes

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

Try it online!

Output

{"":3.3333333333333335}

Olivier Grégoire

Posted 2016-10-25T01:39:24.747

Reputation: 10 647

3Java is the last language I would expect to overload + to String.concat >:^( – cat – 2016-10-26T01:23:55.267

3@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 – 2016-10-26T08:19:32.160

14

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}

jrich

Posted 2016-10-25T01:39:24.747

Reputation: 3 898

You could turn this into an arrow function to remove 4 bytes. – DanTheMan – 2016-10-25T02:00:31.543

1Can you have an empty key? (e.g. remove a) – Conor O'Brien – 2016-10-25T02:08:20.837

_=>\{"a":${_}}`` results in {"a":undefined}, which is exactly 15 characters. Noted that you don't use any input when calling this function – Bassdrop Cumberwubwubwub – 2016-10-25T10:48:02.740

1@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 – 2016-10-25T12:03:42.770

3Remove the a to make the key the empty string, a valid key in JSON. 1 less byte. – kamoroso94 – 2016-10-25T13:25:52.390

Does it have to be a function at all? Can't it just be the `{"":${9e9}}`. – Robert Hickman – 2016-10-25T16:44:59.050

How does this print out anything? It's a function that isn't being called. You should at least add (...)() to it. And then you only have a return value, and not something printed out – nl-x – 2016-10-26T15:34:13.993

@nl-x, oh yeah. I wasn't paying enough attention to the "print" part of the challenge. In a javascript console, it will implicitly return the result of any expression, so I was thinking that might be sufficient, but yeah... no so. – Robert Hickman – 2016-10-26T16:52:39.467

@nl-x The OP has edited to clarify that functions returning the string are allowed. – ETHproductions – 2016-10-26T17:06:18.817

@RobertHickman ^ – ETHproductions – 2016-10-26T17:06:26.013

This is a lot similar to http://codegolf.stackexchange.com/a/97426/14732 (which was answered 1 hour before your last edit.) On a regular environment, without any library, both answers are identical. On a website that happens to have jQuery, both are different. I'm not accusing of anything, I'm just exposing this bit.

– Ismael Miguel – 2016-10-26T21:23:34.633

@IsmaelMiguel That's fair... not sure what I should do about it though. You can see the edit history to see that my original version was a bit longer, but I edited it to reflect Neil's suggestion – jrich – 2016-10-26T21:26:29.423

@jrich I know. I don't know what you should do either. I would upvote the other answer and show this on meta and ask for guidance. – Ismael Miguel – 2016-10-26T21:28:10.173

14

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.

user59178

Posted 2016-10-25T01:39:24.747

Reputation: 1 007

"" is a valid JSON key. – Lynn – 2016-10-25T13:39:05.487

12

Brainfuck, 50 bytes

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

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

Sp3000

Posted 2016-10-25T01:39:24.747

Reputation: 58 729

11

Pyth - 5 bytes

Prints {"'abcdefghijklmnopqrstuvwxyz'": 10}.

XH`GT

Try it online here.

Maltysen

Posted 2016-10-25T01:39:24.747

Reputation: 25 023

JSON only allows double quotes unfortunetly – Downgoat – 2016-10-25T03:21:47.310

@Downgoat ah, fixing for one byte. – Maltysen – 2016-10-25T03:22:15.237

@Downgoat fixed. – Maltysen – 2016-10-25T03:22:53.650

10

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

Conor O'Brien

Posted 2016-10-25T01:39:24.747

Reputation: 36 228

9

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.

Steven H.

Posted 2016-10-25T01:39:24.747

Reputation: 2 841

9

Batch, 16 bytes

Prints {"Windows_NT":0}.

@echo {"%OS%":0}

Neil

Posted 2016-10-25T01:39:24.747

Reputation: 95 035

Could you please add the (example) output? – grooveplex – 2016-10-26T21:15:28.560

8

///, 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
}

manatwork

Posted 2016-10-25T01:39:24.747

Reputation: 17 865

1That's a clever way to save bytes :-) – ETHproductions – 2016-10-25T13:49:06.610

2You can save another one with /a/{":1234}/aa (outputs {":1234}{":1234}) – ETHproductions – 2016-10-25T14:41:55.873

Amazing, @ETHproductions. Thanks. – manatwork – 2016-10-25T15:12:25.017

7

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}")

Billywob

Posted 2016-10-25T01:39:24.747

Reputation: 3 363

1You 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 – 2016-10-25T11:47:21.127

7

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.

Matt

Posted 2016-10-25T01:39:24.747

Reputation: 1 075

6

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}

Emigna

Posted 2016-10-25T01:39:24.747

Reputation: 50 798

6

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!

Dom Hastings

Posted 2016-10-25T01:39:24.747

Reputation: 16 415

5

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.

James

Posted 2016-10-25T01:39:24.747

Reputation: 54 537

I was expecting the 0 byte one :P – Maltysen – 2016-10-25T03:23:48.617

1@maltysen I did post it. I deleted it because it used single quotes instead of double... :( – James – 2016-10-25T03:32:27.800

5

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>

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

1The assignment is to output something. without the alert() you are not outputting anything – nl-x – 2016-10-26T16:01:15.487

1@nl-x The OP has edited to clarify that functions that return the string are allowed. – ETHproductions – 2016-10-26T17:08:24.750

5

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

Adám

Posted 2016-10-25T01:39:24.747

Reputation: 37 779

4

Ruby, 19 bytes

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

Output:

{"1":387420489}

dkudriavtsev

Posted 2016-10-25T01:39:24.747

Reputation: 5 781

@NathanMerrill Fixed – dkudriavtsev – 2016-10-25T02:11:06.117

1Can you show what it outputs – curiousdannii – 2016-10-25T03:11:31.693

Can't you save a byte by removing the space after puts? – Oliver Ni – 2016-10-25T03:49:52.203

I think that ?1*9 is still long enough. – Lee W – 2016-10-25T17:29:00.310

@curiousdannii Done – dkudriavtsev – 2016-10-25T18:57:09.577

@Oliver I did that – dkudriavtsev – 2016-10-25T18:57:20.513

@LeeW Fixed it. – dkudriavtsev – 2016-10-25T18:57:31.973

4

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

DanTheMan

Posted 2016-10-25T01:39:24.747

Reputation: 3 140

4

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

JDL

Posted 2016-10-25T01:39:24.747

Reputation: 1 135

1Sorry, what? R's grammar changes with locale? – cat – 2016-10-26T01:27:38.873

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 – 2016-10-26T07:23:42.423

@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 – 2016-10-26T11:33:30.833

@Konrad, you might be right. I think I was thinking of "useFancyQuotes" which only affects quote, squote etc. – JDL – 2016-10-26T11:37:17.813

4

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}

Kevin Cruijssen

Posted 2016-10-25T01:39:24.747

Reputation: 67 575

Second solution gives an error – Numberknot – 2016-10-25T08:28:40.410

@Numberknot Fixed and added to the test code – Kevin Cruijssen – 2016-10-25T08:33:43.397

1

"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 – 2016-10-25T09:19:46.650

1Also, 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 – 2016-10-25T09:25:48.307

2@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 – 2016-10-25T09:30:33.307

1Oh, my mistake, I didn't check. – Olivier Grégoire – 2016-10-25T09:31:15.810

4

PHP, 19 bytes

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

Output: {"387420489":1}

https://eval.in/665889

Thanks to manatwork for the tips!

ʰᵈˑ

Posted 2016-10-25T01:39:24.747

Reputation: 1 426

1Your output is 16 characters long, while the requirement is 15. So why not remove that “H”? – manatwork – 2016-10-25T08:33:31.317

BTW, since PHP 5.6 there is a ** operator: pow(9,9)(9**9). – manatwork – 2016-10-25T08:48:37.410

115 chars (not really PHP): {"<?=9**9?>":1} – Loovjo – 2016-10-25T11:06:58.333

3

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.

Bubbler

Posted 2016-10-25T01:39:24.747

Reputation: 16 616

3

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.

PhiNotPi

Posted 2016-10-25T01:39:24.747

Reputation: 26 739

3

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}

simbabque

Posted 2016-10-25T01:39:24.747

Reputation: 487

RIP time dependent answer :( – CalculatorFeline – 2017-06-19T22:50:13.467

@CalculatorFeline hu? – simbabque – 2017-06-19T23:15:29.793

3

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!

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

3

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)

penalosa

Posted 2016-10-25T01:39:24.747

Reputation: 505

@ETHproductions Oops – penalosa – 2016-10-25T20:15:47.077

Is this actually outputting anything? Neil's Batch answer certainly does, but can't remember about any implicit batch output.

– manatwork – 2016-10-26T09:26:31.013

@manatwork Yes it does, since echo is turned on, the current command is echoed, evaluating the OS variable in the process. – penalosa – 2016-10-26T16:39:38.673

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 – 2016-10-26T16:48:19.247

@manatwork Yes, exactly. – penalosa – 2016-10-26T17:07:42.730

3

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.

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

1This absolutely is not valid. All submissions must be in a valid programming language. – Mego – 2016-10-26T05:23:06.060

This is mostly kolmo complexity (mostly, because if it outputs something different it still counts), so I think this could be valid – Destructible Lemon – 2016-10-26T05:34:30.243

@DestructibleWatermelon Using a non-programming language is a standard loophole.

– Mego – 2016-10-26T05:44:39.413

@Mego OP has explicitly allowed non-programming languages now – ETHproductions – 2016-10-27T01:08:33.277

3

Bash, 18 bytes

echo {\"$PATH\":1}

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

Isaac Haller

Posted 2016-10-25T01:39:24.747

Reputation: 31

This is genius. +1. And welcome to the site! – Rɪᴋᴇʀ – 2016-10-29T00:23:21.307

2

TSQL(2016 only), 50 BYTES

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

dfundako

Posted 2016-10-25T01:39:24.747

Reputation: 141

You don't require the AS for the alias and NEWID instead of GETDATE will save a couple as well. – MickyT – 2017-06-20T01:36:48.837

2

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?"}":","));
        }
}

Llew Vallis

Posted 2016-10-25T01:39:24.747

Reputation: 131

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 ==. – None – 2017-06-19T10:19:23.453

Good idea, I'll update the code. I don't know why but I really wanted to make a loop. – Llew Vallis – 2017-06-19T10:20:30.930

You have an accidental \`` left at the end of your golfed code. While removing it, you could also remove the unnecessary{}aroundfor's only statement and change"""'"'`. – manatwork – 2017-06-19T10:26:14.643

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. – manatwork – 2017-06-19T10:35:41.960

Welcome to PPCG! – Martin Ender – 2017-06-19T10:36:18.490

Sorry, @LlewVallis, but my suggestion only saved 7 bytes, as the last one is not compatible with the earlier '"'. But there would be another little trick to recover that 1 character saving: use i only in the key and hardcode the value. i<2?"{":"\""+i+"\":1"+(i>8?"}":","). – manatwork – 2017-06-19T18:16:31.567

@manatwork Just realised, sorry. – Llew Vallis – 2017-06-20T06:52:06.760

2

Jelly, 13 12 bytes

“{"":}”s2jȷ4

TryItOnline!

How?

“{"":}”s2jȷ4 - Main link: no arguments
“{"":}”      - literal ['{','"','"',':','}']
       s2    - split into twos -> [['{','"'],['"',':'],['}']]
         j   - join with
          ȷ4 - literal 10000 -> ['{','"',10000,'"',':',10000,'}']
             - implicit print -> {"10000":10000}

previous (13):

“"11”m0“{:}”j

Jonathan Allan

Posted 2016-10-25T01:39:24.747

Reputation: 67 804

2

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.

ElPedro

Posted 2016-10-25T01:39:24.747

Reputation: 5 301

1

Useless? Why? You can still refer that value by its key and use it: http://pastebin.com/RqbbUBEt

– manatwork – 2016-10-25T10:33:42.967

I guess so. If it is considered acceptable then I'll edit my answer accordingly. – ElPedro – 2016-10-25T10:35:57.583

2

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}

skeevey

Posted 2016-10-25T01:39:24.747

Reputation: 4 139

2Could you provide sample output? – Nathan Merrill – 2016-10-25T14:09:58.007

sure, updated post – skeevey – 2016-10-25T17:48:31.110

2

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!

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

2

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.

coredump

Posted 2016-10-25T01:39:24.747

Reputation: 6 292

2

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}}"

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

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+'}' – caffeinated.tech – 2016-10-26T12:36:42.133

1@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 :) – ETHproductions – 2016-10-26T13:18:51.110

2

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.

DLosc

Posted 2016-10-25T01:39:24.747

Reputation: 21 213

1

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.

12Me21

Posted 2016-10-25T01:39:24.747

Reputation: 6 110

1

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.

FlipTack

Posted 2016-10-25T01:39:24.747

Reputation: 13 242

1

05AB1E, 15 13 bytes

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

Try it online!

{"abcdefghijklmnopqrstuvwxyz":"zyxwvutsrqponmlkjihgfedcba"}

Magic Octopus Urn

Posted 2016-10-25T01:39:24.747

Reputation: 19 422

2Your code outputs single quotes instead of double – user2428118 – 2017-02-02T14:25:40.320

@user2428118 fixed at a -2byte cost. JSON with ' is parsable in some languages though. – Magic Octopus Urn – 2017-02-02T14:57:36.410

1

Tcl, 18 bytes

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

Try it online!

sergiol

Posted 2016-10-25T01:39:24.747

Reputation: 3 055

1

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

Chirishman

Posted 2016-10-25T01:39:24.747

Reputation: 389

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. – Nathan Merrill – 2017-06-20T02:30:44.390

1

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}

Destructible Lemon

Posted 2016-10-25T01:39:24.747

Reputation: 5 908

1

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>

Conor O'Brien

Posted 2016-10-25T01:39:24.747

Reputation: 36 228

1

Addict, 200 167 bytes

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!

ETHproductions

Posted 2016-10-25T01:39:24.747

Reputation: 47 880

1

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.

Zatherz

Posted 2016-10-25T01:39:24.747

Reputation: 111

1

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è;':@'{"
}

Mego

Posted 2016-10-25T01:39:24.747

Reputation: 32 998

1

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.

nl-x

Posted 2016-10-25T01:39:24.747

Reputation: 306

2You need to either define a function, or a full program (with printing). – Nathan Merrill – 2016-10-26T16:40:59.023

@NathanMerrill allmost all other javascript/ecmascript solutions do no printing. The rule about function or program was added later. – nl-x – 2016-10-31T08:46:24.570

I guess it's a REPL? – l4m2 – 2018-04-20T12:46:11.417

1

ECMAScript 2015, 16 bytes

_=>`{"":${9e9}}`

It will run in most modern ECMAScript environments (eg. Firefox, Chrome, MS Edge, Opera, Node…).

Toothbrush

Posted 2016-10-25T01:39:24.747

Reputation: 3 197

1

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]".

Travis J

Posted 2016-10-25T01:39:24.747

Reputation: 141

1

Actionscript 3, 27 bytes

trace(JSON.stringify(int));

outputs

{"MAX_VALUE":2147483647,"length":1,"MIN_VALUE":-2147483648,"prototype":{}}

Brian

Posted 2016-10-25T01:39:24.747

Reputation: 231

1

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}

Travis J

Posted 2016-10-25T01:39:24.747

Reputation: 141

Cool. Do you need the 0 in 1.0, or will 1./0 suffice? – ETHproductions – 2016-10-28T23:34:47.923

1./0 is a syntax error in c#, namely "Identifier expected". Nice thought though :) – Travis J – 2016-10-28T23:55:05.323

1

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

Noodle9

Posted 2016-10-25T01:39:24.747

Reputation: 2 776

Doesn't seem to work the same way here: http://pastebin.com/P5vau3WB

– manatwork – 2016-10-31T08:59:26.477

@manatwork Works with QPython on my android – Noodle9 – 2016-10-31T10:52:37.640

@manatwork And Python 2.6.6 but not Python 2.7.1 – Noodle9 – 2016-10-31T13:03:02.453

1

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());
}

Harald Korneliussen

Posted 2016-10-25T01:39:24.747

Reputation: 430

0

Text, 15 Bytes

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

{"hi ":"world"}

Mega Man

Posted 2016-10-25T01:39:24.747

Reputation: 1 379

0

Prolog (SWI), 19 bytes

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

Try it online!

ASCII-only

Posted 2016-10-25T01:39:24.747

Reputation: 4 687

0

Vim, 13 bytes

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

output:

{"aaaaaaaaa":0}

JoshM

Posted 2016-10-25T01:39:24.747

Reputation: 379

0

Perl, 18 bytes

say"{'".[2]."':1}"

Prints an array reference in quotes as the name and 1 as the value. Sample output:

{'ARRAY(0x60002b5c0)':1}

Gabriel Benamy

Posted 2016-10-25T01:39:24.747

Reputation: 2 827

12This isn't valid JSON because strings must be delimited with double quotes (not single quotes as you currently have it). – PhiNotPi – 2016-10-25T02:56:08.653

Chrome console accepts it just fine – Gabriel Benamy – 2016-10-25T03:06:15.200

5

@GabrielBenamy Unfortunately, standard JSON is different from Javascript objects, and doesn't allow single quotes. Source: http://www.json.org/

– DanTheMan – 2016-10-25T03:34:42.530

If you're changing the quotes anyway, you can remove the 2 in the [] and it'll still be an arrayref for -1! – Dom Hastings – 2016-10-25T07:18:32.777

2Another alternative: say"{\"$~\":$]}"! – Dom Hastings – 2016-10-25T07:24:03.067

You can save one byte by using a scalar ref, but then you need commas. say"{'",\2,"':1}" – simbabque – 2016-10-25T11:54:06.640

AFAIK is still invalid. -1. – CalculatorFeline – 2017-06-19T22:41:20.650

0

C++11, 30 bytes

As unnamed lambda, port of jrich's answer, -1 byte thanks to ETHproductions

[](){printf("{\"\":%f}",9e9);}

Usage:

int main(){
 [](){printf("{\"\":%f}",9e9);}();
}

Karl Napf

Posted 2016-10-25T01:39:24.747

Reputation: 4 131

0

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

Magic Octopus Urn

Posted 2016-10-25T01:39:24.747

Reputation: 19 422

Your program should take no input. – Nathan Merrill – 2016-10-25T17:02:47.133

@NathanMerrill fixed, the only cool part to my answer is the Grails part anyway. – Magic Octopus Urn – 2016-10-25T17:05:05.123

0

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

Roman Gräf

Posted 2016-10-25T01:39:24.747

Reputation: 2 915

I forgot about the qoutes and noticed ah I need 11 chars as key. – Roman Gräf – 2016-10-25T19:25:41.640

{":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... – ETHproductions – 2016-10-25T19:33:55.103

Yes I tries some copy-pasting but got the same problem you got. :( – Roman Gräf – 2016-10-25T19:34:48.210

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... – ETHproductions – 2016-10-25T19:39:54.077

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. – Roman Gräf – 2016-10-25T19:43:10.913

I think it's <kbd> – ETHproductions – 2016-10-25T19:44:42.190

say @p gives >= 15 bytes of JSON?! – cat – 2016-10-26T01:26:08.287

@cat No. It prints your username. Which can be set to any string you want. – Roman Gräf – 2016-10-26T06:29:49.797

0

Pyke, 11 10 8 bytes

~C`0]]1Y

Try it here!

Blue

Posted 2016-10-25T01:39:24.747

Reputation: 26 661

0

C#, 76 bytes

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

Output:

{"":0.333333333333333}

RobIII

Posted 2016-10-25T01:39:24.747

Reputation: 397

1If I'm not mistaken, you can omit the using System; and use instead System.Console.Write(...). This can save you 6 bytes – auhmaan – 2016-10-28T15:30:21.463

1@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! – RobIII – 2016-10-28T16:41:02.513

0

Ruby (cheap), 22 bytes

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

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

dkudriavtsev

Posted 2016-10-25T01:39:24.747

Reputation: 5 781

"a":"b"*8 would be shorter. – Magic Octopus Urn – 2016-10-27T17:45:34.900

@carusocomputing See my other post. – dkudriavtsev – 2016-10-27T19:16:31.920

0

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.

user8397947

Posted 2016-10-25T01:39:24.747

Reputation: 1 242

0

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}

Steve Bennett

Posted 2016-10-25T01:39:24.747

Reputation: 1 558

“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. – manatwork – 2016-10-31T09:01:18.790

Hmm I was considering the REPL as a language. – Steve Bennett – 2016-10-31T12:48:24.937