2

I have a program that can output results either as JSON or Python data structure literals. I am wondering how to succinctly name the latter option.

user7610
  • 25,267
  • 15
  • 124
  • 150
  • 6
    JavaScript literals are not called JSON. JSON derived its name and syntax from JavaScript, but they’re not the same thing. Use “Python literals”. – Ry- Oct 25 '17 at 19:02
  • what's a python object 'literal' though? if you're outputting the object in JSON, that's a string that represents a javascript object (it's a form of serialization). How are you serializing your python object when you're not outputting it in JSON? – cowbert Oct 25 '17 at 19:06
  • 2
    Relevant: [What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/q/2904131/218196) – Felix Kling Oct 25 '17 at 19:06
  • "Python literals" is a bit wordy for my purposes. And it's good call that this is not precisely defined. For my uses, it is JSON, except True and False are capitalized, and there are null values written as None. Otherwise it is JSON. – user7610 Oct 25 '17 at 19:13
  • @cowbert: It’s not “a string that represents a JavaScript object”. It’s JSON. You can serialize the same data types represented (maps of string keys/arbitrary values, strings, numbers, booleans, nulls, and lists of values) as Python literals. – Ry- Oct 25 '17 at 19:32
  • huh? JSON is a way to serialize a javascript object into a string. Are you referring to `repr()`/`__repr__()` in Python for your definition of emitting a "python literal"? – cowbert Oct 25 '17 at 19:34
  • Essentially this oneliner (not my code) https://github.com/rh-messaging/cli-rhea/blob/28c6c2fed1a38744d013575bc3ace5235d41cf4b/client-lib/formatter.js#L231 and I am perfectly aware that way it can go horribly wrong in many circumstances and does not withstand any maliciousness whatsoever. – user7610 Oct 25 '17 at 19:44
  • @user7610. You are converting a json string to what is effectively a python module containing a `dict`. Presumably, you want users to be able to import this module as normal python code. So why not just call it "pyth**on**" (as opposed to "js**on**")? – ekhumoro Oct 25 '17 at 19:50

1 Answers1

2

JavaScript literals are not called JSON. JSON derived its name and syntax from JavaScript, but they’re not the same thing. Use “Python literals”.

Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Well, it will be name of command line switch. `--out=json` will be the non-default. I was thinking to name the Python output `--out=repr`, after the `reprlib` module in Python 3. It will be on by default, so it should not matter is is a bit obscure, people won't write it explicitly. – user7610 Oct 25 '17 at 19:06
  • 2
    @user7610: `repr` seems perfectly fine to me, given that that's the name of the module. – Felix Kling Oct 25 '17 at 19:09