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.

https://i.sstatic.net/2SMY0.png

https://i.sstatic.net/l9nFp.png

https://i.sstatic.net/n9t8Q.png

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

Tips for managing a date picker with JavaScript using the Selenium WebDriver

I have been attempting to scrape a travel website using Selenium Webdriver and Python. While I have successfully set the destination (destino) and place of origin (origem), I am encountering difficulties when trying to select a date. I understand that Ja ...

How does a web worker behave when the owner is not actively engaged?

[edit: I am using Chrome 49.0.2623.112 m (64-bit) with default settings and HTTPS, but the issue occurred before the switch.] My application utilizes web workers to handle AJAX polling. While this may not provide a significant performance boost, it does e ...

Tips for making a horizontal grid layout with three items in each row

I have a scenario where I need to render a group of Player components using map() loop, and I want them to be displayed horizontally side by side using a Grid component from material-ui. Currently, the components are rendering in a vertical layout: https ...

The $(window).load(function() function is unable to run once the entire document has finished loading

I have not been able to find the solution in the following circumstances: In an HTML document, I successfully load multiple other HTML files. However, within one of these included HTML files, specifically "navmenu.html," I want to execute a script with a ...

Consolidating JSON files into a unified CSV

I have numerous json files that I need to consolidate into a single csv file. I've tried the code provided, but it's not accomplishing what I need. The desired output can be found in this csv file: here Any suggestions on how to achieve the desi ...

Utilizing Flutter and Dart to efficiently convert JSON time series data into a map structure containing key-value pairs

Encountered a message regarding "anonymous closure" in the TimeSeriesAdjusted.fromJson method, indicating a subtype error that I'm having trouble identifying. [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: type 'Null' is not a subtyp ...

Guide on adjusting the language settings for notifications in chosen.js?

Is it possible to customize the error message that appears in chosen.js when an unavailable option is typed into the multiple select box, which currently says 'No results match "query"'? ...

Error: The property 'rtl' is not defined and cannot be read

I'm currently in the process of developing a vuejs component library that utilizes vuetify 2.1.4 and attempting to import it into another application locally through npm link. However, I'm encountering numerous errors such as TypeError: Cannot ...

Unleashing the Power of Aurelia's HTML Attribute Binding

I need to bind the "required" html attribute in my template and model. Along with passing other information like the label value using label.bind="fieldLabel", I also want to pass whether the element is required or not. However, simply using required="tr ...

The v-select function organizes data based on the content of "item-text"

I created a v-select component using Vuetify, and I am wondering how I can sort the names of the items from largest to smallest within this v-select? <v-select v-model="selectedFruits" :items="fruits" label="Favorite Fruit ...

Exploring the capabilities of referencing MongoDB documents with the populate method in Node.js

I have been working on referencing in Node.js using the populate method, but I am unsure about how exactly it works. In my code, I am creating a reference to the user collection from my child collection. I have two collections - one for children and anothe ...

Arrange the grid in a pleasing manner

I'm really struggling with this issue. In my current setup, I have a Grid container that holds two separate grids - one for a textfield and another for a checkbox. Unfortunately, I can't seem to get them to align properly. <Grid container& ...

Having trouble opening a JPEG file that was generated using the Writefile Api in Ionic-Cordova

Currently, I am using the writeFile API to create a JPEG image. The process is successful and the image is stored in the directory as expected. However, when I try to open the file manually from the directory, I encounter an error message saying "Oops! Cou ...

"Node NPM encounters difficulty in importing package using only its name and not the complete path

Currently facing an issue with my newly created Node Package while trying to share a project I'm working on. Specifically, I am encountering difficulties with the require statement. Project: https://github.com/kcjonson/indigo The problem lies in req ...

Different ways to modify the color and thickness of a variable in HTML5 with either JavaScript or CSS

I am currently working with a JavaScript file where I have a variable defined as follows: var nombre = document.getElementById('nombre').value; The 'nombre' variable corresponds to an element in an HTML file: Nombre: <input type=" ...

How can I limit auto-search results to a specific city in India on Google Maps?

How can we restrict autosearch to only Pune city in India? I attempted the following: autocomplete.setComponentRestrictions( {'country': ['in']},{'city':['Pune']}); ...

Implementing a permanent class following an incident

Is it possible to dynamically add a class to an element when an event occurs rather than based on a condition? For example, I have a td that displays a variable. <td>{{myVar}}</td>//myVar=10 When the variable changes to myVar=15, I want to ad ...

Navigating to the parent node in a treeview within the wijmo flex grid: a step-by-step guide

Utilizing the wijmo flex grid, I've successfully created a tree view for my data. I can determine if a specific node has children and its level, but I'm struggling to navigate to the parent node from a given one. Additionally, I am able to retrie ...

Determine in JavaScript whether a character is 32-bit or not

Is there a way to determine if a specific character is 32 bits using JavaScript? I attempted to use charCodeAt() but it was unsuccessful for identifying 32-bit characters. Any guidance or assistance on this matter would be greatly valued. ...

Obtaining a file from the Firebase database

After successfully implementing the login functionality in my app, I am now attempting to retrieve the user's document in order to display their name on the page. email = loginemail.value; password = loginpassword.value; signInWithEmailAndPass ...