0

What naming conventions are people using for variables that hold JSON-serializable objects? We'd like the name of the variable to remind us to only store information in the object that can be serialized into JSON without losing information. Applications include HTTP sessions, non-searchable database columns, data logging, and serializing restorable application state.

The obvious contenders, at least from the perspective of someone programming in Javascript for node.js, seem to fall short:

  • prefixJSON - JSON is actually a serialization syntax, so this would properly be a string in JSON format, not an object
  • prefixInfo - info is often used in node.js for any kind of map, including ones that take functions and instances of ES6 classes.
  • prefixMap - Same issue as the info suffix
  • prefixData - Doesn't really suggest a constraint on the type

The best I can do is prefixJSONInfo, prefixJSONData, or prefixJSONObject, but I was hoping for something more succinct and readable. The prefix may be lengthy and descriptive too.

This question mainly applies to programming languages that support variant-type variables, such as Javascript. These variables are meant to hold a mishmash, but the programmer needs to be reminded to limit the types of values that are thrown into the mishmash.

Joe Lapp
  • 2,435
  • 3
  • 30
  • 42
  • Not to be confused with naming conventions for the constituent values of JSON objects, which are addressed here: http://stackoverflow.com/questions/5543490/json-naming-convention – Joe Lapp Jun 30 '16 at 21:38
  • I'm finding several libraries for strongly-typed languages using the class names JSONObject and JSONArray. These seem to be the standard names for the two most common JSON-serialized types. – Joe Lapp Jun 30 '16 at 22:34
  • There's a strange phenomenon in example code throughout the net that sets a variable to a ``new JSONObject()``: most of these variables are named "object" or "obj". All instances of classes are objects, but it's the JSONObject instances that get labelled as being of type "object." I'm seeing the variable names ``object``, ``obj``, ``jsonObject``, ``jsonObj``, and even just ``jo``. – Joe Lapp Jun 30 '16 at 22:48

1 Answers1

2

In this case, it seems that a specific acronym might serve a good purpose.

JSONSerializable

written:

JSS or Jss

Examples:

prefixJss

customerDataJss

sessionInfoJss

Or maybe even:

JSONSerializableObject

prefixJSO

prefixJso

My $0.02. This might be more opinion based, as I don't think there are any globally accepted standards for these things. There are best practices, such as you mentioned (like short but descriptive). It's up to the developer or team to determine which short and descriptive versions they like (team preference).

Trust me tho, I understand how difficult naming things is sometimes. :)

ryancdotnet
  • 2,015
  • 16
  • 33
  • Hey, I like this! Maybe we need to create a convention, as you're proposing. A non-standard suffix certainly will cause programmers to pause. I'll give others some time to weigh in too. Thank you! – Joe Lapp Jun 30 '16 at 21:50
  • Along these lines, JSON stands for JavaScript Object Notation, so before we've serialized into the notation, we have a JavaScript Object, or JSO. There are several ways to make JSO work, making it a strong candidate. Awesome! – Joe Lapp Jun 30 '16 at 22:22
  • JSObj may be the best approach. It embodies the various meanings of JSO while also being suggestive. JSO isn't exactly recognizable without the N. See my OP comment on how code throughout the net seems to suggest that JSON objects are of type "object." – Joe Lapp Jun 30 '16 at 23:01