Is it possible for me to use any text as a JSON key?

Is it acceptable to use any utf-8 string as a property name in JSON? For example, is the following valid:

var personData = {
    'Matti Möttönen': {
        "FirstName": "Matti",
        "LastName": "Möttönen",
    },
...

Currently, I am utilizing Vue.js and retrieving data from a flat file.

Answer №1

Absolutely, it is possible:

let userInformation = {
    'John Doe': {
        "FirstName": "John",
        "LastName": "Doe",
    },
}

or alternatively

let userInformation = {
    ['John Doe']: {
        "FirstName": "John",
        "LastName": "Doe",
    },
}

and you can access it like this

userInformation['John Doe']

Answer №2

Referencing this source,

In the realm of programming, a property consists of a "key: value" duo where the key is a string (referred to as a "property name") and the value can take on any form.

To respond to your inquiry, it should be perfectly fine as long as you utilize strings as keys.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to integrate Javascript code with a React component?

I need to find a way to include this block of code in just one specific React component. Any suggestions? <!-- Create a button that your customers click to complete their purchase. Customize the styling to suit your branding. --> <button sty ...

What are the best ways to suggest modifications to RFC(s) regarding JSON in order to incorporate feedback and comments?

After coming across several RFCs related to JSON, I began pondering the best approach for suggesting a modification to the grammar or parser sections to introduce support for comments. JSON currently does not officially allow comments, but I believe ther ...

What steps can be taken to resolve the TS5023 error that arises when including "allowImportingTsExtensions" in the tsconfig.json file?

While working on my React project, I've encountered a specific error that reads: Could not parse tsconfig.json. Please ensure it contains valid JSON syntax. Details: error TS5023: Unknown compiler option 'allowImportingTsExtensions'. I tr ...

Collection of items consists of identical objects repeated multiple times

Multiple objects are being created and then pushed into the array objArr: var objArr = []; var obj = {}; var height = [9,8,7,3,6,5,2,4]; for (var i = 0; i < 8; i++) { debugger; var mountainH = height[i]; obj.h = mountainH; obj.index = i; o ...

Conceal four input fields depending on the option chosen from the dropdown menu

I need assistance with hiding multiple input boxes. Although I've tried using if and else, it seems to only work for two of the boxes. My current code is written in regular JavaScript, but I am open to exploring a jQuery solution as well. window.onlo ...

Keep the link underlined until a different button is pressed

I need help with a webpage that displays a list of partners organized by categories. When clicking on sidebar categories, the link remains underlined. However, if you click anywhere else on the page, the link becomes inactive. CSS: button:hover { t ...

Convert a CSV file into JSON format using RxJava2

[UPDATED] Greetings I am faced with the task of converting the data from a CSV file into JSON format based on a Java class, using RxJava2. To illustrate, here is an example of how the CSV file is structured: 1,John,Smith The Java class called User has ...

The leaflet_Ajax plugin is constantly searching for the default marker symbol located at js/images/marker-icon.png

Although I'm relatively new to Leaflet, I have experience creating interactive maps in the past. Recently, I've been working on a project involving displaying GPS data from a UAV. The UAV transmits location information to a server, which then ret ...

Why isn't my content appearing correctly on different pages?

This ecommerce site is my very first project using React. I have created pages for Contact, Login, and more. The footer and other components display correctly on the home page, but when navigating to other pages, the content appears shortened. For referen ...

Attempting to understand how to retrieve specific items from my MongoDB Database that are associated with a particular user based on their ID

I've been attempting to retrieve specific items (Portfolio pics) that have been submitted by a user from my Mongo Database. However, when I checked the extracted items using Console logs, it seems to display all portfolio pieces for every user instead ...

Building interactive forms in Angular 6

I want to design a dynamic form that creates a new form when the AddNew button is clicked. In my TypeScript (ts) file, I have the following code: addinfoForm: FormGroup; infoNameList: FormArray; infoModel: Productdetail; constructor(private fb ...

Revise the modal window

I need help with switching between two modal windows for registration and login. How can I make the modal window change when the "Sign Up" button is clicked? Here is the link to my project: https://jsfiddle.net/Alienwave/0kqj7tr1/4/ Vue.component('s ...

Function "Contains" not Present in Object

Upon executing the code provided below, I encounter the following error message. An issue has arisen: Cannot find function contains in object Is Patient Fasting?/# of Hours->Yes; 12 hours. Here is the snippet of my code: var i = 0; var tempF ...

Creating a loading screen in Angular2: Step-by-step guide

How can you best integrate a preloader in Angular 2? ...

Tips for documenting curried functions using Js docs

I'm encountering issues while trying to use Js docs for generating static documentation of my project. When attempting to run the js doc command, I am faced with numerous parse errors specifically in areas where I have curried functions. Strangely, my ...

How can Vue i18n v9 be utilized as a JavaScript object instead of embedding it within the template?

Can Vue and vue-i18n be used with JavaScript objects only, without being included in the template? This code is located in src/boot/i18n.js import { boot } from 'quasar/wrappers' import { createI18n } from 'vue-i18n' import messages fr ...

Error Message: Unable to Load User Profile Pictures from Microsoft Graph

Currently, I am developing an application that makes requests for user profile photos from Microsoft Graph. The process seems to be working smoothly as the request returns a 200 status code and a significant amount of data is retrieved. However, when I att ...

Having trouble getting CSS animation to work on Mozilla using mozAnimationName?

<style> @keyframes shake { 0% { -moz-transform:scale(0);opacity:0; } 25% { -moz-transform:scale(1.3);opacity:1; } 50% { -moz-transform:scale(0.7);opacity:1; } 75% { -moz-transform:scale(2); ...

Tips for accessing a file in AngularJS

Can AngularJS be used to read files? I am interested in placing the file within an HTML5 canvas for cropping purposes. I was considering implementing a directive. Below is the JavaScript code that I plan to include in my directive: function readURL(input ...

Instructions on incorporating a logical condition for an object that is entering a region in motion

I am currently in the process of developing a new game concept. The goal of the game is to maneuver a square across the screen while avoiding raindrops that fall from the top of the canvas. I need assistance with programming the logic so that when a rain ...