Error encountered in Parse cloud code: Unexpected character sequenceJavascript

I am attempting to retrieve information from an httpresponse, parse the JSON, and create a new dictionary with an array of dictionaries similar to:

"data" :   {"infracciones": [
             {
            "folio": "03041487403",
            "fecha": "2014-03-16",
            "situacion": "Pagada",
            "motivo": "POR NO RESPETAR LOS LIMITES DE VELOCIDAD",

        }, 
        {
            "folio": "0334357403",
            "fecha": "2015-04-11",
            "situacion": "Pagada",
            "motivo": "POR NO RESPETAR LOS LIMITES DE VELOCIDAD",

        }],
        "tenencia":[ ...]
 }

However, I am receiving an error: "Unexpected string in main.js:35" and I am unsure of what is causing it. Thank you for any assistance. Below is the code:

Parse.Cloud.httpRequest({
    url: url1 ,
    headers: {
 'Content-Type': 'application/json;charset=utf-8'
    }
    }).then(function(httpResponse) {

        var json = JSON.parse(httpResponse.data);
        var datos = json.infracciones;
        var infracciones = [];
        var data = {};
        var i = 0;
        for(i = 0; i < datos.length ; i++){


            infracciones[i].["folio"] = datos.folio ;  // THIS IS LINE 35
            infracciones[i].["fecha"] = datos.fecha ;
            infracciones[i].["situacion"] = datos.situacion ;
            infracciones[i].["motivo"] = datos.motivo ;

        }

        data.push({
            key : "infracciones",
            value : infracciones

        });


        response.success(data);
        console.log(httpResponse.text);
    }, function(httpResponse) {
      console.error('Request failed with response code ' + httpResponse.status);
});

Answer №1

Give this method a try

let violations = [];
let info = [];
let index = 0;
for(index = 0; index < info.length ; index++){
    violations[index] = {};
    violations[index].folio = info.folio ;
    violations[index].date = info.date ;
    violations[index].status = info.status ;
    violations[index].reason = info.reason ;
}

data.push({
    category : "violations",
    details : violations
});

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

Encountering a Vue.js issue with [Error rendering root instance] because of asynchronous JSON loading

I have a project where I am using Vue.js to build an app. The app retrieves all its data from a JSON file. However, when attempting to load the JSON file using jQuery's getJSON() method, an error occurs during the rendering of the web page. An erro ...

Is Babel necessary for a Node.js server application, and what are the benefits of using it?

My fondness for ES6 syntax and its new object-oriented style makes coding much easier for me. However, as a newcomer to JavaScript, I am curious about the advantages and disadvantages of using Babel in terms of performance, maintenance, readability, and ...

Utilize Google Sheets to import HTML data from Tradingview by clicking on the "load more" button

Currently, I am attempting to pull data from TradingView using the following formula: =importhtml("https://www.tradingview.com/markets/stocks-usa/market-movers-all-stocks/","table",0) Unfortunately, when I try to import the data, only 100 rows are loaded ...

What distinguishes loading angular dependencies and what method is optimal for module sharing?

Can you explain the distinction between these two methods of loading modules? angular.module('CoreApp', ['...','...','...','...']); //parent module angular.module('MainApp1', ['CoreApp' ...

Is there a way to organize items in an array alphabetically according to a predetermined key value?

I have an array of objects containing countries with various values for each country. My goal is to list them alphabetically. // globalBrands { [ { id: 1, title: 'Argentina', content: [{url: 'w ...

Developing HTML5 animation by utilizing sprite sheets

Struggling to create an engaging canvas animation with the image provided in the link below. Please take a look at https://i.stack.imgur.com/Pv2sI.jpg I'm attempting to run this sprite sheet image for a normal animation, but unfortunately, I seem to ...

Making changes to a JSON File

I've been attempting to integrate a jQuery gantt chart into my WordPress website as a plugin. However, I've hit a roadblock when it comes to editing the data.json file. My approach involves using a PHP form to add a new item. Upon form submission ...

Having various ng-apps within a single parent app

Exploring angularjs for the first time and experimenting with multiple ng-apps on a single page. For example, having app2 inside app1 and app1 within rootApp. controller1 includes an $http service that retrieves id and name values and assigns them to $roo ...

Issues with router middleware functionality in Node.js hinder proper operations

Currently, I am working with Nodejs and utilizing "Express js". One of the tasks at hand involves implementing a "Router Middleware" function. With my current code setup, whenever I access "http://localhost:3000", the "router middle" functionality is tri ...

Storing JSON response in memory with Node.js: A handy guide

Hi there! I have a Node.js application where I am calling a route that returns JSON. I'm interested in storing that JSON data in memory. Can anyone suggest the best way to accomplish this in Node.js? ...

Transferring an Object from one AngularJS Controller to Another

Currently delving into the world of AngularJS, I've encountered a seemingly trivial problem with no solution in sight. My issue lies in managing two lists/controllers created by a factory service. Specifically, I'm facing difficulties removing ...

When Flexigrid is loaded using $(document).Ready(), it will not load again if called by another function outside of $(document).Ready()

I have developed a function named "loadTimeTrackersGrid()" that is responsible for loading a flexigrid. Here is how the setup looks: $(document).ready(function () { var editTrackerID = 0; loadTimeTrackersGrid(); )}; The initial section o ...

What is the process for performing a redirection in Node JS?

I have been working on a task to redirect a page to the home page with the route '/search' upon form submission. Within my submit.html file, there is a form that utilizes the '/submit' post method to submit the form data when the submit ...

Validation Express; the error variable is not defined in the EJS

Struggling with a perplexing issue that has been eluding me for quite some time now, I am hopeful that someone out there might be able to provide me with some guidance. The variable (error) that I am passing in the res.render{} object seems to be unattain ...

Using the increment operator within a for loop in JavaScript

this code snippet causes an endless loop for (let i = 0; ++i;) { console.log(i) } the one that follows doesn't even run, why is that? for (let i = 0; i++;) { console.log(i) } I want a thorough understanding of this concept ...

Numeric Input Box: Show gaps

I have numeric input boxes in my HTML/PHP/JS application where users will be entering numbers with 4 to 7 digits. However, I want the users to see spaces between every third digit for better readability. For instance, User types: 8000 Us ...

Incorporating Button Value from Anchor Tag Title Upon Page Load

Currently, I am working on a real estate project and facing an issue with a contact modal box. My goal is to extract the title from tag "a" and place it as the button value in the modal box. English isn't my strong suit, so please excuse any errors i ...

What's the best way to organize Python objects for optimal JSON serialization?

Recently transitioning from JavaScript to Python, I am facing a challenge in understanding how to effectively communicate between client and server using JSON. Specifically, I am struggling to find the equivalent of an easily jsonifyable object attribute i ...

The deletion of property '1' from the [object Array] is not possible

How to Retrieve a List in My Components Using Input : @Input() usersInput: Section[]; export interface Section { displayName: string; userId: number; title: number; } Here is the Value List : 0: displayName: "بدون نام" ...

What is the most effective method for achieving a desired outcome?

Is it a valid approach to get an action result, and if so, how can this be achieved? For instance, if there is a page with a form for creating entities, after successfully creating an entity, the user should be redirected to the entity's detail view. ...