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

Tips on properly declaring props in Typescript when a parent component is passing props down to its children componentsуж

When a parent component clones its children to pass props to them, how can we specify the type of props for the children? I'm encountering an issue because injectedProps is expected in the Child component const Parent: React.SFC<ParentProps> = ...

unable to access objects in JavaScript due to an error

The JSON data I received from PHP is shown in this image: Now, I need to access all the data from the JSON file. In my current situation, I am trying to compare the existing data with the JSON data. However, I encountered a small error where not all of m ...

Steps to generate a json file using python

Based on the fields given below: url ="example.com" ssl = "yes" tags = [{'html':'hello'},{'title':'Welcome to My Site'},{'h2':'Introduction'},{'p':'Hey there&apo ...

Utilizing dynamic JSON lists in Spring MVC

Currently, I have a new form for Person that includes a table of objects structured like so: <table class="table table-striped table-condensed flip-content"> <thead class="flip-content"> <tr> <th width="20%"> ...

An easy guide to using validators to update the border color of form control names in Angular

I'm working on a form control and attempting to change the color when the field is invalid. I've experimented with various methods, but haven't had success so far. Here's what I've tried: <input formControlName="pe ...

Error encountered: Module 'redux-saga/effects' declaration file not found. The file '.../redux-saga-effects-npm-proxy.cjs.js' is implicitly typed as 'any'. Error code: TS7016

<path-to-project>/client/src/sagas/index.ts TypeScript error in <path-to-project>/client/src/sagas/index.ts(1,46): Could not find a declaration file for module 'redux-saga/effects'. '<path-to-project>/client/.yarn/cache/red ...

What is the correct way to express an object in an array?

I've encountered an issue: I'm working with an array called _daysConfig<DayConfig> When I manually populate it like this, everything functions correctly: _daysConfig: DayConfig[] = [ { date: new Date('Wed Jul 22 2020 21:06:00 GMT+02 ...

Using Typescript to define custom PopperComponent props in Material UI

I'm currently utilizing the Material UI autocomplete feature in my React and Typescript application. I'm looking to create a custom popper component to ensure that the popper is full-width. Here's how I can achieve this: const CustomPopper ...

Querying an ASP.NET API using a JSON request

Here is some JSON data that I need to work with: { "0": { "id": 0, "type": "camera", "option": [ { "optionId": 1, "optionValue": "", "answered": "false", ...

Optionalize keys containing a specific character in their name

Imagine I have an object similar to the following: const obj = { a: 1, "b?": 2, "c?": 3 } The current type of this object is as follows: type Obj = { a: number; "b?": number; "c?": number; } Is there a ...

jQuery/JSON Error: Unexpected character encountered during parsing

I am currently working on MVC4 and I am attempting to transfer data from a view to a controller using JQuery and JSON. The objective is to extract the values of checkboxes within a grid. Here is the code snippet: <script type="text/javascript"> func ...

Jersey allows for easily sending both image and JSON data together in a multipart response

Currently, I am in the process of learning Jersey by working on creating a Rest service that can receive an image from a client, process it, and then return a new image with additional information related to the processing. The uploading functionality is w ...

Removing specific items from an array by using the splice() method based on a certain condition

I am attempting to use a for-loop to remove all items that meet a certain condition in the state array. However, it seems to only be removing the last items from the array rather than those that match the condition. Could it be that I am using .splice() ...

Generating and traversing a JSON object with three dimensions

After exploring various topics on this site, I haven't been able to find a clear solution for my specific problem. I am facing a scenario where I need to populate three select boxes with options from a multidimensional array that follows the structur ...

Exploring Angular14: A guide to efficiently looping through the controls of strictly typed FormGroups

Currently, I am working on upgrading my formGroups to be strictly typed in Angular v14. Within my FormGroup, there is a specific block of logic that iterates through all the controls and performs an action (this part is not crucial as I am facing issues be ...

Guide to specifying the indexer type of a function argument as T[K] being of type X in order for t[k]=x to be a permissible expression

Currently, I am attempting to create a function that can alter a boolean property within an object based on the provided object and property name. While I have found some helpful information here, the function body is still producing errors. Is there a way ...

Search for specific item within an array of objects

Working on an Angular project, I am attempting to remove an object from an array. To achieve this, I need to filter the array and then update the storage (specifically, capacitor/storage) with the modified array. Here is my function: deleteArticle(id: str ...

Retrieve data from TypeScript file (.ts) and use it in an HTML document

Recently I started learning Typescript and HTML as I work on building an Angular2 application. At the moment, I have a TypeScript file that resembles the following structure: import {Http, Headers} from 'angular2/http'; import {Component} from & ...

PHP encountering a bad escaped character while parsing JSON using JSON.parse

I'm encountering an issue with JSON parsing. In my PHP code, I have the following: json_encode(getTeams(),JSON_HEX_APOS); This returns a large amount of data. Sample data: To provide more clarity, let's assume I have this: my_encoded_data ...

retrieving information from an array nested within a JSON object in an Angular application

I am struggling to retrieve two specific values from a JSON object. The content of the JSON is as follows: [ { "type":"session_start", "properties":[ { "property":"activity&q ...