Oops! There seems to be an issue with an invalid character in the literal true value while making a POST request to the API with JSON data. The expected character should be

Can anyone help me solve an issue I am facing while trying to use the POST method to insert data using JSON in JS code? When I attempt the transformation, I receive an error message stating:

"ERROR: invalid character ' ' in literal true (expecting 'e')".

If you have any insights on how to resolve this problem, please let me know.

const obj = {
  "num_matricula": num_matricula,
  "limit_date": "2022-05-20",
  "admission_date": admission_date,
  "cost_center": cost_center,
  "pos_number": pos_number,
  "role": role,
  "department": department,
  "pagamento": {
    "vinculo": vinculo,
    "valor": valor,
    "recorrencia": recorrencia,
    "contaBancaria": {
      "banco": "001",
      "carta": "c9160763-db6c-4e8c-a1ad-ad8709c99be2"
    }
  },
  "deficiencia": deficiencia,
  "jornada": jornada,
  "profile": {
    "name": name,
    "email": email,
    "mobile": mobile
  },
  "exame": {
    "clinica": "6dc84ce4-7d9f-48ec-b9b1-a8a895a21fd4",
    "data": "2022-05-15",
    "hora": "14:00",
    "obs": "Comparecer de manhã",
    "guia": "e37dab24-c7a4-4b92-b9d1-32ed538b8300",
  },
  "docs": ["c9e26093-5e0c-4bd2-bea3-ac5182a6179f"],
  "send_sms": true,
  "send_email": true
};
const myJSON = JSON.stringify(obj);

Some columns already have data from a previous step as shown in the images linked below. In the JS code, I have repeated the column names because of this. Also, note that the boolean data types for columns are send_email, send_sms, and deficiencia.

Answer №1

An issue arises with JSON when it is treated as a string. As evidenced by the first line of code, it becomes apparent that the following is not valid JSON: "num_matricula": num_matricula,

It is important to note that only numerical values can be used without double quotes in JSON format: "num_matricula": 1234,

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

Dividing the logic from the Express router while retaining the ability to utilize Express functionalities

As I embark on my journey of developing my first app using Node.js and Express, I have noticed that my router file is starting to get overcrowded with logic. It seems like there is too much going on in there. My solution to this issue is to pass a functio ...

Querying an array using the Contentful API

Recently, I've been experimenting with the Contentful API (content delivery npm module) and have encountered a challenge that I'm not sure how to overcome. In my Contentful setup, I have a content type called tag which consists of one field, als ...

Sharing tips for sending error objects to a socket.io callback

Utilizing callbacks with socket.io Client side code : socket.emit('someEvent', {data:1}, function(err, result) { console.log(err.message); }); Server side code : socket.on('someEvent', function(data, callback) { callback(ne ...

Retrieving data from a PHP object

I'm facing a challenge trying to extract the genre value from an object generated by this tool library that fetches json data from 'The Movie Database'. I'm currently struggling with Object-oriented PHP and any guidance would be greatly ...

Is it possible for Vue data to be handled asynchronosly

Have you ever wondered? Is it possible for Vue's data function to be asynchronous? Imagine needing to fetch data from an API using a library like axios, which only offers async methods. How can this data be loaded into Vue's data function? Con ...

Tips on separating a function into two separate files in Node.js

Hey there! I am just starting to explore Node.js so bear with me if I make any mistakes. So, I have this file: exports.Client = function() { this.example = function(name, callback) { console.log(name); }; ...

What is the best way to showcase Vue data of a selected element from a v-for loop in a

Here is an example of how my json data is structured. I have multiple elements being displayed in a v-for loop, and when one is clicked, I want to show specific information from that element in a modal. [{ "id": 1, "companyNa ...

Displaying data-table with only the values that are considered true

Right now, I am utilizing the AgReact table to exhibit data fetched from my endpoints. The data-table is functioning properly, however, it seems to be unable to display false values received from the endpoints on the table. Below are the snippets of my cod ...

My JSON API request is returning a 500 error code, what could be the issue here?

I am currently working on implementing a new client in my API using php cURL. All clients, products, and any other entities are created using the POST method. Below is the code snippet I am using: $json='{ "data": { "type": &qu ...

Unable to extract a particular value from a JSON data structure

This situation has been on my mind for a good couple of hours now. I have this json object with example values like so: { "events": [ { "id": 64714, "live": false, "start": "1399117500", "league_ ...

The viewport width in NextJS does not extend across the entire screen on mobile devices

I'm currently tackling a challenge with my NextJS Website project. It's the first time this issue has arisen for me. Typically, I set the body width to 100% or 100vw and everything works smoothly. However, upon switching to a mobile device, I not ...

Experience seamless slide transitions with the react-slick carousel using scroll events in React JS and JavaScript

Currently utilizing the carousel library found at: react-slick I am interested in enabling mouse scroll functionality to navigate through each slide. The idea is to scroll up to progress forward and scroll down to go backward. Came across a relevant exa ...

Searching recursively for keys with empty values in an array using Javascript

I've written a function that recursively locates empty values in a nested array. The function initially produces the correct value, but it seems to reset it to the input value before returning the result. What could I be overlooking? Below is my co ...

Exploring the world of color in Google visualization charts

I am currently working on a project that requires me to add different colors to specific zones on a graph. I am looking to use colors such as blue, red, yellow, and green. Here is the outcome I have achieved: I am aiming for something similar to this des ...

Tips on using the .map() method to extract data from a JSON response received from a get request and utilizing the content within a specific index to populate table rows

Here is the JSON response representation, https://i.stack.imgur.com/0QWkv.png This is how my project displays it: https://i.stack.imgur.com/LnA5v.png The rendering code snippet is as follows: render() { const { materials } = this.state; ...

Component fails to re-render after token refresh on subsequent requests

Here is my axios-hoook.js file, utilizing the axios-hooks package. import useAxios from 'axios-hooks'; import axios from 'axios'; import LocalStorageService from './services/local-storage.service'; import refreshToken from &ap ...

I am unable to retrieve the information for the object in a JSON format

I have a JSON file containing an object { "id": 387, "name": "flatFive", "coordinates": { "x": 9.6, "y": 2.2 }, "creationDate": { "year": 2020, "monthValue": 4, "month": "APRIL", "dayOfMonth": 1, "dayOfYear": 92, "dayOfWeek": "WEDNESDAY", ...

Having difficulty applying capitalization to the initial word in an input using JavaScript/jQuery

I've read through several other discussions on this forum regarding the same issue. My problem lies in capitalizing the first letter of an input. Here is the link to my code on JSFiddle Despite my efforts, I can't seem to get the substr() funct ...

Python: Flattening and Extracting specific JSON segments

I've got an input JSON that has the following structure: > {"payment": {"payment_id": "AA340", "payment_amt": "20", "chk_nr": "321749", "clm_list": {"dtl": [{"clm_id": "1A2345", "name": "John", adj:{"adj_id":"W123","adj_cd":"45"}}, {"clm_id": "999 ...

Analyzing the string's worth against the user's input

I need help figuring out how to save user input on a form (email and password) as variables when they click "Register", so that the data can be used later if they choose to click "Login" without using default information. I am working on this project for s ...