Format for lists and dictionary responses

Author: SamMousaCreated Jan 4, 2022Updated Jun 2, 2022
LabelsFeatureRequestUnplanned

I think a somewhat simpler/easier way forward would be to restrict the output format of the existing commands from YAML to JSON. This ought to be a backwards-compatible change, since all YAML parsers are supposed to be able to read JSON. However, it would be worth testing the major client languages to double-check that they actually do the right thing in that case.

Originally posted by @kr in https://github.com/beanstalkd/beanstalkd/issues/610#issuecomment-1003193205

I've thought some more on this and I think going either the YAML or the JSON road is troublesome unless you want to pull in a proper library into beanstalkd.

We could actually simplify the formats as well, since the beanstalkd protocol is a text based protocol and requires a custom parser / interpreter it's not much work to define the lists and dictionaries.

Lists:

  • All entries are strings
  • Each entry is separate by a \n

This gives you all you need to know, no parsing and more importantly no escaping required.

Dictionary:

  • Each entry has a key and a value
  • Since we control the keys we can just put strict definitions on them; keys only consist of the alphabet a-z and the character -.
  • Values should be interpreted as string unless we specify that they are some other type explicitly.
  • Keys and values are separated by a :

These could have trivial implementations in beanstalkd code and to not break existing clients we could implement these as new commands. For example stats-tubes-2 or stats-2.

For me this has no priority by the way, I'm happy parsing the YAML in it's current state and since I'm assuming developers create tube names in a reasonable way (not containing user input) it should cause no issues.