I encountered this string that looks like JSON syntax but I've never seen a property with a colon before it and not with a backwards greater than or equals sign:

Badge {

Is it a JSON string and if so what does the colon do?

  • I think that's Ruby. Where did you find the code? Apr 9, 2019 at 1:20
  • It was output to the console during an upgrade of Discourse Apr 9, 2019 at 1:43
  • github.com/discourse/discourse ... Discourse is about 65% ruby by weight (according to GitHub). Apr 9, 2019 at 1:45
  • 1
    Badge is the name of the class. I updated my answer with a link to the file that defines the class. The hash literal is valid Ruby, but a human would be more likely to use the key: value syntax. Apr 9, 2019 at 1:51

2 Answers 2



Knowing more about the context (message written to console during an updgrade of discourse), you likely saw an instance of this class being printed.

I think you are looking at Ruby code, although it is strange to mix symbol literals and =>.

  • An identifier beginning with a colon is a :symbol literal.
  • A key-value pair in a hash table can be written key => value or key: value, but the latter syntax only works with symbol literals.
  • Badge doesn't have parentheses after it and you can omit parentheses.

Some other languages use => to separate key value pairs, here's why the other likely suspects don't fit.

  • Perl: A key begining with : must be quoted. Bare identifiers and bare identifiers with a leading - are the only things that do not need to be quoted in Perl in this context.
  • PHP: PHP allows {} for accessing array values $a{6}, but does not allow braces for array literals. Also, you can't leave the parentheses off a function call in PHP.

Colon variable refers to :abc type variables you might have seen in Ruby. They are called Ruby symbols.

A Ruby symbol is not a variable because it cannot be assigned a value.

Also, a Ruby symbol is not a reference to another variable nor is it a pointer to a memory location.

Still a symbol has a value and whenever the name of the symbol is same, its value is the same.

An example will make it more clear.

# It is trivial to assign a value to a variable.
abc = "1"
=> "1"

# But a symbol cannot be assigned any value.
:a = "1"
# SyntaxError: A symbol cannot be assigned a value

# Can use a variable as a map-key 
m = {abc => "1"}
=> {"1"=>"1"}

# Can use a string as a map-key 
=> {"def"=>"1"}

# Can also use a symbol as a map-key 
m = {:a => "1"}
=> {:a=>"1"}

# Can use same symbol as key in another map
m2 = {:a => "2"}
=> {:a=>"2"}

# And it won't affect the previous map.
=> {:a=>"1"}

=> {:a=>"2"}
  • So is a symbol comparable to a constant? Apr 12, 2019 at 23:37
  • No, a symbol in Ruby is comparable to a symbol in Lisp or in Scala. A Ruby symbol is a datatype that represents the concept of a "name" or a "label", just like a Ruby string represents the concept of "text" or a Ruby integer represents the concept of, well, "integer". Sep 11, 2020 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.