Dealing with problematic JSON data in Google Apps Script

Struggling to extract the "oid" value from a JSON response using Google script for the first time. The original parsed JSON response is as follows:

{btcs=0.01000000, orders=[{amount=0.10000000, price=2000.00000000, oid=592589, type=1}], plns=0.00440603}

Directly attempting to retrieve the oid resulted in an empty variable. However, when parsing with "orders":

   oid = raw_data["orders"]; 
   oid = JSON.stringify(oid)
   oid = oid.toString().replace("[", "");
   oid = oid.toString().replace("]", "");

The result was:

{"oid":"592589","type":1,"amount":"0.10000000","price":"2000.00000000"},

Even after adding:

oid = oid["oid"]; 

To the parsed "orders," the oid variable remained empty. Attempting to directly retrieve the oid from parsed "orders" without replacing "[" and "]" also did not populate the oid variable.

Answer №1

Retrieve the specific array element directly:

let orderId = rawData.orders[0].orderId;

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

Checking for Age Validity with Formik and Yup: How to Ensure a Date Represents Someone Who is Eighteen Years Old or Older

I'm currently working on a form using Formik, Yup, and ReactJS. Specifically, I am focusing on the date field validation to ensure that the user is at least 18 years old. Within the validationSchema parameter in Formik, I have included the following c ...

Retrieve the specific file path of a dependency within the node_modules directory

Can you help me find the exact path of a dependency within a specific node_modules package? Here's an example setup: |- node_modules/ |- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a4b5b7bfb5b3b1f9b594e6fae5fae4"& ...

The challenges encountered with JSONP/Ajax Script - displaying 'Undefined'

I need help retrieving data from a webserver that I don't have control over. I've searched online but haven't found a solution yet. I've tried various codes, with and without DataTables. If anyone could provide guidance on where to go ...

The console is showing messages before the task is completed

When using console.log to write detailed messages about the current task expected to be performed by Protractor, I noticed that these messages are appearing on the console before the actual task is executed in the browser. An example of this is: it(' ...

How to flip the value in v-model using VueJS

Below is the code snippet that I am working with: <input v-model="comb.inactive" type="checkbox" @click="setInactive(comb.id_base_product_combination)" > I am looking to apply the opposite value of comb.inactive to the v-model. Here are m ...

Implementing a Response to an AJAX POST Request with Servlets

I have a unique situation where I need to validate a username input in a text box. The process involves sending the entered username to a server for checking if it has already been taken by another user. If the username is available, I want to change the b ...

issue with vue-html2pdf when using Persian language

Is there a solution for handling Persian language issues in vue-html2pdf? Or is there another module that can convert VUE to PDF without any problems with RTL language support? ...

Ways to trigger a 406 Error (Not Acceptable) using jQuery

Currently, I am implementing error handling in my.js file. This involves making cross-domain calls to another server and utilizing Mustache.js for dynamic HTML templates. $.getJSON(url, function(data, textStatus, xhr) { $.each(data, function(i, data) { ...

"Using JavaScript to initiate a popup window that displays a specific destination link

Whenever I view this code, the iframe popup automatically opens. But I want the iframe to open only when I click the "click me" button. Can someone please assist me with this? I believe it's a simple trick, but as a JavaScript amateur, I am struggling ...

Is it possible to make an element float or stay fixed on a web page based on the visible section of the page?

This question may be a bit confusing, but I couldn't phrase it any other way. Check out this link: Configure - Apple Store (U.S.) On the webpage, the 'Summary' box is positioned below the sub-header and aligns with the content block. When ...

The art of properly parsing JSON in AngularJS

Still a newbie in AngularJS, but I am determined to learn. Currently, I have the following controller set up. It retrieves JSON data from a specified URL. app.controller('PortfolioItemCtrl', ['$scope', '$routeParams', &apos ...

What steps can I take to address the issue with the capitalization checker?

I've encountered a challenge with my TodoList Project which you can find here: https://codepen.io/BerkayAkgurgen/pen/OJRqjPg. I am aiming to avoid duplicate words from being added to the list as items. To tackle this, I have been using the "toLowerCas ...

Is there a way to use Jest to test a Vuex action that contains an API call?

ASYNC ACTION VUEX : Here we have an asynchronous action that is called from the component. It includes a function fetchGaragesData which sends an API request to fetch data from the server. [ACTION_TYPES.FETCH_CASHLESS_GARAGES]: async ( { dispatch ...

React array hooks are failing to function as expected, causing updated values to not appear on the screen

import React, { useState } from 'react'; import Tab from 'react-bootstrap/Tab'; import Tabs from 'react-bootstrap/Tabs'; import { sections } from '../../data/sections'; export const NavigationTop = () => { c ...

Activate a modal component in ReactJS when a click event occurs

I'm having trouble integrating ReactStrap Modal into my NavBar and I haven't found a solution yet. I created a handler function to be triggered on a click event, but I can't figure out how to call my login component from this handler functio ...

Tips for fixing the AnguarJS $injector:modulerr problem (more information provided)

Lately, I've been struggling with implementing custom directives for my web application. Upon checking the JS console in Chrome, an error message pops up saying Failed to instantiate module w2l-direc due to: {1}. It appears that there may be an issue ...

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="e19 ...

There is an issue with the syntax in your for-loop control where a closing parenthesis is missing

When I try to navigate through the arrays from 1 to 4 in the given JSON data, Firebug shows me an error message: SyntaxError: missing ) after for-loop control [Break On This Error] for( x in LGIntake.corpCodeOptions.marketSegment.1){ StartI...aseId=0 ...

Having trouble removing items from the data grid list in react material-ui, any thoughts on what might be causing the issue?

I'm facing an issue with deleting items from a basic list of customers rendered using material UI DataGrid. Even though I can retrieve the specific customer id when logging to the console, I am unable to delete the item from the list. You can view my ...

Tips for delaying the execution of the next code block until a request.get function is completed in node.js

I am a newcomer to NodeJS and I am currently tackling an issue with the request.get method. My objective is to create a function that sends a web request, and once the request is completed, the function should return the result, otherwise it should return ...