---
title: "How to represent key-value pairs in a JSON object, and can keys be of different data types?"  
description: "How to represent key-value pairs in a JSON object, and can keys be of different data types?"  
author: "Utpal Vishwas"  
published: 2023-10-10  
updated: 2023-10-11  
canonical: https://www.mindstick.com/forum/160088/how-to-represent-key-value-pairs-in-a-json-object-and-can-keys-be-of-different-data-types  
category: "json"  
tags: ["javascript", "json", "jsonobject"]  
reading_time: 2 minutes  

---

# How to represent key-value pairs in a JSON object, and can keys be of different data types?

How to represent key-[value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) pairs in a [JSON object](https://www.mindstick.com/forum/699/how-to-parse-into-json-object-using-json-parse-in-node-js), and can [keys](https://www.mindstick.com/articles/75385/full-product-keys) be of different [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) types?

## Replies

### Reply by Aryan Kumar

Key-value pairs in a [JSON](https://www.mindstick.com/forum/34446/convert-json-string-to-object) object are represented as follows:

- A key is a string enclosed in double quotation marks.
- A colon **:** separates the key from its corresponding value.
- The value can be of any valid JSON data type, including strings, numbers, objects, arrays, booleans, and null.

Here's an example of how key-value pairs are represented in a JSON object:

```plaintext
{
  "name": "John",
  "age": 30,
  "isStudent": false,
  "address": {
    "street": "123 Main St",
    "city": "New York"
  },
  "hobbies": ["reading", "hiking"]
}
```

In this example, the JSON object contains multiple key-value pairs:

- **"name": "John"**: The key is a string, and the value is also a string.
- **"age": 30**: The key is a string, and the value is a number.
- **"isStudent": false**: The key is a string, and the value is a boolean.
- **"address": {...}**: The key is a string, and the value is another JSON object (nested object).
- **"hobbies": [...]**: The key is a string, and the value is a JSON array.

Regarding the data types of keys in JSON objects:

- JSON keys must be strings. While the values can be of various data types, JSON object keys are always represented as strings.

For example, you cannot have keys of different data types like this:

```plaintext
{
  "name": "John",
 30: "age"   // Invalid: Key must be a string
}
```

In this example, **30** is not a valid key because keys in JSON must be strings. JSON is designed to be a simple and predictable data format, and key names are always strings.


---

Original Source: https://www.mindstick.com/forum/160088/how-to-represent-key-value-pairs-in-a-json-object-and-can-keys-be-of-different-data-types

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
