Values that you can call JSON

2024/02/17

Let’s actually write down the rule for what values inside a program we call JSON and what values we don’t call JSON. I don’t know if there are any other guidelines out there, but I’ve decided for myself at least. This is matter of taste in metonymy.

The rule

Value What to call it
Data encoded in JSON Call it JSON
The kind of data that JSON can encode Don’t call it JSON

Examples

const a = '{"port": 3000}';
const b = JSON.parse(a);
const c = {port: 3000};
const d = {"port": 3000};
const e = JSON.stringify(c);
const f = require('./config.json');
const g = await (await fetch('http://localhost:3000/config')).json();
const h = /\s+/g;
const i = {source: h.source, flags: h.flags};
const j = JSON.stringify(i);
const k = JSON.parse(j);
const l = new Regexp(k.source, k.flags);

a is a string of JSON-encoded data. It’s JSON.

b is a value decoded from JSON. It’s not JSON.

c is a value that can be expressed in JSON. It’s not JSON.

d is a value created from a literal, where the literal is valid JSON. It’s not JSON.

e is the result of encoding something in JSON. It’s JSON.

f is a value loaded from a JSON file, which is already decoded. It’s not JSON.

g is a value received from a server that is sent encoded in JSON and then decoded, and it’s additionally the result of a method named json. It’s not JSON.

h is a value that can’t be expressed in JSON. It’s not JSON.

i is a value specially created for the purpose of serializing something in JSON. It’s not JSON.

j is result of encoding that special value in JSON. It’s JSON.

k is a value specially created for the purpose of deserializing something from JSON. It’s not JSON.

l is a value that can’t be expressed in JSON. It’s not JSON.

What to call values that aren’t JSON

Say more when it is JSON

Extra note, when you say “You get the info in JSON,” you really should be saying “You get a User object in JSON. What? No I don’t have documentation for it. You’ll have to get one and figure it out. Oh and some of the numerical fields are strings, so watch out for that.”

My last post was about either Why picking up a plate doesn’t make a sound but putting it down does or Receiving a truncated HTTP response in Node.js. Find out which.