Grateful
Grateful

Reputation: 10175

Can JSON values be numbers?

Can JSON values (not keys) be numbers, or do they HAVE to be strings only? So the following is valid.

{"number":"6"}

But is the following also valid?

{"number":6}

Upvotes: 1

Views: 3096

Answers (3)

Kevin Smith
Kevin Smith

Reputation: 14436

Json values can be

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null

See - https://www.w3schools.com/js/js_json_datatypes.asp

Upvotes: 0

SubjectX
SubjectX

Reputation: 896

It is valid JSON syntax. But beware that different programming languages will parse JSON differently..

https://www.freeformatter.com/json-validator.html

Upvotes: 2

Kahn Kah
Kahn Kah

Reputation: 1453

In JSON, 6 is the number six. "6" is a string containing the digit 6. So the answer to the question "Can json numbers be quoted?" is basically "no," because if you put them in quotes, they're not numbers anymore.

The only thing that needs to be between quotes is the property name (number).

Upvotes: 1

Related Questions