What sets apart a JSON Key that is enclosed in double quotes "" from one that has no quotes?

Below is my TypeScript object:

{
      first_name:"test",
      last_name: "test",
      birthdate:"2018-01-08T16:00:00.000Z",
      contactNumber: "12312312312",
      email:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e195849295a195849295cf828e8c">[email protected]</a>",
      username:user."test",
      password: user."test"
}

VERSUS

{
    "first_name":"test",
    "last_name": "tests",
    "birthdate":"2018-01-08T16:00:00.000Z",
    "contactNumber": "31231232131",
    "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afcac2cec6c3efc8c2cec6c381ccc0c2">[email protected]</a>",
    "username":"test",
    "password":"test1234"
}

Whenever I make an HTTP POST request with this object using Angular 5, it triggers an error on the API side.

The error message is as follows:

Unpermitted parameters: :first_name, :last_name, :birthdate, :contactNumber, :user

To resolve this issue, adding double quotes to all keys in the object fixes the problem.

Answer №1

It is important to adhere to the JSON specifications outlined on http://json.org, which require keys to be enclosed in double quotes.

A JSON object consists of a series of string/value pairs, with strings defined as:

A string is a collection of zero or more Unicode characters contained within double quotes and may include backslash escapes.

This format allows you to use reserved keywords as keys, such as:

{
    "function": "sqrt"
}

In essence, any "JSON" code with keys not encapsulated in double quotes would not qualify as legitimate JSON.

Answer №2

The solution is illustrated in the initial sketch on the JSON website: object keys ought to be represented as strings within JSON. If they are labels (rather than strings), then it does not conform to JSON standards, but rather signifies a direct Javascript object.

It appears that the Ruby software library responsible for handling API requests comprehends the data you transmit (a Javascript object) and transforms the keys into Ruby symbols. The validation process anticipates the keys to be strings (as they are decoded from valid JSON format), which explains the error message being displayed.

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

Which is more suitable for storing data for boardgame session data: redisJSON or traditional redis?

Recently set up a Redis server for my backend using ioredis. I've discovered that if I want to store data in JSON format, I need to use the redisJSON module because hashes are only string typed and flat. However, since I'm only storing one objec ...

What distinguishes between a public variable declared as var: any = []; versus a public variable declared as var: any[] =

I'm seeking clarification on the distinction between the following: public var: any = []; // versus public var: any[] = []; ...

What could be preventing the array from updating after subscribing to the service?

Attempting to fetch a list of movies from a Web API server on my localhost. The server does provide data when called with a Get request using the HttpClient module, but struggling to display it. MovieList Component import { Component, OnInit } from &apos ...

What is the best way to retrieve a cookie sent from the server on a subdomain's domain within the client request headers using getServerSideProps

Currently, I have an express application using express-session running on my server hosted at api.example.com, along with a NextJS application hosted at example.com. While everything functions smoothly locally with the server setting a cookie that can be r ...

Next.js is faced with a frustrating issue where images and videos are failing to display

I've been working on my Next.js 13 project with TypeScript, eslint, and Chakra UI, but I'm facing an issue with images and videos not displaying. Despite trying both the HTML <img> tag and importing Image from Chakra, the problem still per ...

Create Office Script calculations with quotations included

I am currently attempting to create an Excel office script formula for a cell. Are there any tips on how to insert a formula with quotes into a cell? For example, the following works fine: wsWa.getCell(WaRangeRowCount, 9).setFormula("= 1 + 1"); ...

To achieve the desired format, where should I press or manipulate the information?

I need help with manipulating arrays to generate a specific JSON file structure. I've made some progress but got stuck at this point: var T_nn_IN = document.getElementById('datatablenewname'); var tabledata_newname_initialname = []; ...

receiving an undefined value from a remote JSON object in Node.js

I have been struggling to extract the specific contents of a JSON api without success. Despite my best efforts, the console always returns undefined. My goal is to retrieve and display only the Question object from the JSON data. After spending several h ...

Exploring discrepancies in JSON arrays using Lodash

Using lodash to find the difference between two arrays: c1Arr contains: [ { varName: 'city', varValue: 'cccccccc' }, { varName: 'country', varValue: 'dddddddd' } ] c2Arr contains: [ { varName: 'abc', ...

Executing TypeScript Mocha test cases using ES6 modules

Setting up mocha tests for the TypeScript App in my Rails application has been a bit of a challenge. Initially, I added a basic test to kick things off, but encountered the following error: /home/bernhard/Programs/ruby/cube_trainer/jstests/utils/optional. ...

The type 'Dispatch<SetStateAction<boolean>>' cannot be assigned to type 'boolean'

Currently, I am attempting to transfer a boolean value received from an onChange function to a state variable. let [toggleCheck, setToggleCheck] =useState(false);` <input type="checkbox" id={"layout_toggle"} defaultChecked={toggleCh ...

"Unlocking the Power of Pandas Dataframes: A Guide to Parsing MongoDB

I have a piece of code that exports JSON data from a MongoDB query like this: querywith open(r'/Month/Applications_test.json', 'w') as f: for x in dic: json.dump(x, f, default=json_util.default) The output JSON looks like this: ...

Navigating through API replies

I am attempting to iterate through an API response in order to display unique, non-repeating ip-srcs and their corresponding values. I have successfully made the API call in Python and formatted the output as JSON, but I am struggling with filtering the di ...

A guide on setting up a countdown timer in Angular 4 for a daily recurring event with the help of Rxjs Observable and the Async Pipe

I'm currently working on developing a countdown timer for a daily recurring event using Angular 4, RxJS Observables, and the Async Pipe feature. Let's take a look at my component implementation: interface Time { hours: number; minutes: numbe ...

Issue with Retrofit2 implementation of Query parameters

Here is a JSON response containing information about different books. [ { "title" : "Clean Code", "author" : "Robert Martin", "bookUrl" : "http://amzn.to/1DJybxH", "imageUrl" : "http://adavis.github.io/adept-android/images/clean_code.jpg", "displayDate" ...

Exploring the use of Jest for testing delete actions with Redux

I've been working on testing my React + Redux application, specifically trying to figure out how to test my reducer that removes an object from the global state with a click. Here's the code for my reducer: const PeopleReducer = (state:any = init ...

What is the best way to incorporate an AJAX GET request into an HTML element?

Currently, I am attempting to execute a JavaScript code that will convert all <a></a> elements found within another element <b></b> (the specific name in the HTML) into links that trigger an HTTP get request. However, the code I hav ...

Sending JSON Data from Angular2 Component to Node.js Server

Currently, I am facing an issue where I am unable to successfully insert data into a database using Angular2 and Node.js. Upon running my script, I use console.log(this.address); to verify that I am passing json, and the output in the console is as follow ...

Generating perspectives from a HashMap contained within an ArrayList

I've been struggling with this logic problem, but I believe I'm getting closer. I am extracting values from a JSON response and storing them in a HashMap before adding the HashMap to an ArrayList. doInBackground protected String doInBackground( ...

Searching for particular information within an array of objects

Seeking guidance as a newbie on how to extract a specific object from an array. Here is an example of the Array I am dealing with: data { "orderid": 5, "orderdate": "testurl.com", "username": "chris", "email": "", "userinfo": [ ...