🌐
Oracle
docs.oracle.com › en › database › oracle › oracle-database › 23 › adjsn › json-data.html
JSON Developer's Guide
August 7, 2024 - JSON Syntax and the Data It Represents Standard JSON values, scalars, objects, and arrays are described.
🌐
W3Schools
w3schools.com › js › js_json_syntax.asp
JSON Syntax
JSON data is written as name/value pairs (aka key/value pairs).
text-based open standard designed for human-readable data interchange
whitespace
object
combox respuesta json
JSON (JavaScript Object Notation, pronounced /ˈdʒeɪsən/ or /ˈdʒeɪˌsɒn/) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of name–value pairs … Wikipedia
Factsheet
JavaScript Object Notation
Filename extension .json
Internet media type application/json
Factsheet
JavaScript Object Notation
Filename extension .json
Internet media type application/json
🌐
JSON
json.org
JSON
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999.
🌐
W3Schools
w3schools.com › js › js_json.asp
W3Schools.com
JSON is similar to the syntax for creating JavaScript objects.
Top answer
1 of 2
41

Well, you can't. As you said, you can represent arrays and dictionaries. You have two choices.

Represent the set as an array. Advantage: Converting from set to array and back is usually easy. Disadvantage: An array has an implied order, which a set doesn't, so converting identical sets to JSON arrays can create arrays that would be considered different. There is no way to enforce that array elements are unique, so a JSON array might not contain a valid set (obviously you could just ignore the duplicates; that's what is likely to happen anyway).

Represent the set as a dictionary, with an arbitrary value per key, for example 0 or null. If you just ignore the values, this is a perfect match. On the other hand, you may have no library support for extracting the keys of a dictionary as a set, or for turning a set into a dictionary.

In my programming environment, conversion between set and array is easier (array to set will lose duplicate values, which either shouldn't be there, or would be considered correct), so for that reason I would go with arrays. But that is very much a matter of opinion.

BUT: There is a big fat elephant in the room that hasn't been mentioned. The keys in a JSON dictionary can only be strings. If your set isn't a set of strings, then you only have the choice of using an array.

2 of 2
12

Don't try to represent sets in JSON. Do it when parsing the data instead.

Your JSON data should have a schema which specifies which fields should be treated as a set, or you may have a metadata embedded in the JSON data itself that describes when a list should be treated as a set (e.g. {"houses": {"_type": "set", "value": [...]}}) or with a naming convention.

Note that according to JSON standard, a JSON object can have duplicate keys. ECMA-404 wordings:

Objects

[...] The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs. These are all semantic considerations that may be defined by JSON processors or in specifications defining specific uses of JSON for data interchange.

AFAICD, nothing in the spec forbids non unique names, and there are many JSON parser implementations that can parse non unique object names. RFC 7159 discourages non unique names for interoperability, but specifically don't forbid it either, and goes on to list how various parsers have been seen handling non unique object names.

And ECMA 404 also doesn't require that array ordering be preserved:

Arrays

The JSON syntax does not define any specific meaning to the ordering of the values. However, the JSON array structure is often used in situations where there is some semantics to the ordering.

This wording allows applications to use arrays to represent sets if they so choose.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or ...
Find elsewhere
🌐
Wikipedia
en.wikipedia.org › wiki › JSON
JSON - Wikipedia
March 6, 2005 - The current ECMA standard states, "The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs." Objects are delimited with curly brackets and use commas to separate each pair, while within each pair, the colon ":" character separates the key or name from its value.
🌐
Elementor
elementor.com › blog › resources › what is json? a web creator’s guide to syntax, examples, and data exchange
What Is JSON? A Web Creator's Guide to Syntax, Examples, and Data Exchange
1 month ago - A JSON object represents a collection of related data. You can think of it as a dictionary, a directory, or a set of properties. Syntax: An object always starts and ends with curly braces: { }.
🌐
IETF
datatracker.ietf.org › doc › html › rfc8259
RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format
It is derived from the object literals ... Third Edition [ECMA-262]. JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays)....
🌐
Codefinity
codefinity.com › courses › v2 › d797f15f-39dd-4abc-8cfd-0d898dd2b885 › 372339e2-bcc5-490c-a5ee-f4d51f680045 › 87de75f0-f4f0-4c43-9fb8-ccbf095a6816
Learn Common JSON Syntax Mistakes | Understanding JSON Data
JSON supports numbers, strings, arrays, objects, booleans, and null values, but it does not allow comments, functions, or undefined values. Arrays and objects can be nested, but every string must be wrapped in double quotes.
🌐
RestfulAPI
restfulapi.net › home › json › json syntax
JSON Syntax
November 3, 2023 - A JSON document may contain information separated by the following separators or tokens. 1. JSON name-value pairs example Name-value pairs have a colon between them as in "name" : "value". JSON names are on the ... Read more
🌐
Bornoe
bornoe.org › blog › 2023 › 05 › the-basics-of-json-syntax
The basics of JSON syntax – Bornoe.org blog
November 30, 2023 - The value can be of any JSON data type, including objects or arrays. ... The keys must be strings and are followed by a colon : to separate them from their corresponding values. Multiple key-value pairs are separated by commas. The syntax for an object is as follows:
🌐
Hostinger
hostinger.com › home › tutorials › what is json: understanding syntax, storing json data and downloadable cheat sheet
What Is JSON? Syntax, Examples + Cheat Sheet
September 9, 2025 - JSON syntax consists of two core elements – values that are one of the six available data types and keys that are strings.
🌐
Micro Focus
microfocus.com › documentation › silk-performer › 195 › en › silkperformer-195-webhelp-en › GUID-6AFC32B4-6D73-4FBA-AD36-E42261E2D77E.html
JSON Object Structure
A JSON object contains zero, one, or more key-value pairs, also called properties. The object is surrounded by curly braces {}. Every key-value pair is separated by a comma.
🌐
HashiCorp Developer
developer.hashicorp.com › terraform › configuration language › syntax › json configuration syntax
JSON Configuration Syntax - Configuration Language | Terraform | HashiCorp Developer
November 19, 2025 - Learn about the JSON-compatible language syntax, including file structure, expression mapping, block mapping, and block-type-specific exceptions.
🌐
JSON
json.org › example.html
JSON Example
This page shows examples of messages formatted using JSON (JavaScript Object Notation) · The same text expressed as XML:
🌐
JSON Formatter
jsonformatter.org
Best JSON Formatter and JSON Validator: Online JSON Formatter
JSON Validator Online checks the integrity/syntax of the JSON data based on JavaScript Object Notation (JSON) Data Interchange Format Specifications (RFC).
🌐
JAXB
javaee.github.io › tutorial › jsonp001.html
Introduction to JSON
JSON defines only two data structures: objects and arrays. An object is a set of name-value pairs, and an array is a list of values.