Issues arise when parsing JSON in order to extract the response from the webpage

When I receive this web page response:

{"Status":"OK","RequestID":"xxxxxxxxxx","Results":[{"SubscriberKey":"teste132133","Client":null,"ListID":0,"CreatedDate":"0001-01-01T00:00:00.000","Status":"Active","PartnerKey":null,"PartnerProperties":null,"ModifiedDate":null,"ID":0,"ObjectID":null,"CustomerKey":null,"Owner":null,"CorrelationID":null,"ObjectState":null,"IsPlatformObject":false}],"HasMoreRows":false}

I want to extract the SubscriberKey, which is like : "SubscriberKey":"teste132133"

However, when I attempt to use Parse Json, it seems that there might be a mistake in my code. Here's what I have tried :

<script language="javascript" runat="server">

Platform.Load("Core","1");
  
var response = HTP.Get("https://xxxxxxxx.pub.sfmc-content.com/vjpsefyn1jp"); //web page link
var obj = Platform.Function.ParseJSON(response);
Write(obj.Results[0].SubscriberKey)

</script>

Answer №1

My expertise lies in client-side JavaScript. I have a solution that might be helpful for you. This approach involves using the fetch function to retrieve the response and then extracting the JSON value from it. By utilizing an asynchronous function call, we can also utilize the await keyword to enhance code readability.

<script type="module">
async function getSubscriberKey() {
   const response = await fetch("https://xxxxxxxx.pub.sfmc-content.com/vjpsefyn1jp")
   const json = await response.json()
   const Results = json.Results
   const subscriberKey = Results[0].SubscriberKey
   return subscriberKey;
}
const key = await getSubscriberKey();
console.log(`The subscriber key is: ${key}`);
</script>

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

PHP: Avoiding duplicate JavaScript imports

Hey there, I'm running into an issue with incorporating JavaScript, specifically the Google Maps API. Let's say I have a page that includes the library like this: <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=pla ...

Transform a string into an array in PostgreSQL json(b) and then update the corresponding field

In my PostgreSQL database, there is a jsonb field with the following content: { "object": { "urls": "A;B;C" } } My objective is to modify the value of urls within the object and convert the semicolon-separated string into a JSON array. The desired result ...

Having trouble retrieving list data in JSON response while utilizing the ASP.NET Web API in MVC

In my Project, this is the JavaScript code: function RetrieveData() { debugger; var url = 'http://localhost:50951/api/Home'; $.ajax({ type: "GET", url: url, ...

Struggling to implement a Rock Paper Scissors game using HTML, CSS Bootstrap4, and JavaScript, specifically facing challenges in getting the function to select a new image

Recently, in my coding class, we were tasked with creating a program that would display images of dice and generate random numbers when the refresh button was clicked. To practice using querySelector and setAttribute, I decided to expand on the lesson by i ...

Issues arise when attempting to implement a basic quiz using jQuery or JavaScript

I’ve created a quick quiz to determine how many correct answers a person gets when they click the 'submit' button. However, it keeps showing zero as the result. Can someone please assist me? $(document).ready(function(){ $('button' ...

Guidelines for aligning backend timer with a mobile application

I'm currently working on an app that randomly selects a user and provides them with a 15-second timer to respond. The user's app checks the database every 5 seconds to determine if they have been chosen. Once chosen, the mobile app initiates a 15 ...

Steps for making a webpack-bundled function accessible globally

I am currently working with a webpack-bundled TypeScript file that contains a function I need to access from the global scope. Here is an example of the code: // bundled.ts import * as Excel from 'exceljs'; import { saveAs } from 'file-save ...

What changes can I make to this jquery code to utilize a background image instead of a background color?

Can someone help me modify this snippet to set a background-image instead of changing the background color? <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("#button_layer").hide(); $("#im ...

What is the best way to add information to a specific array inside an object?

I am facing an issue with pushing data to the "data" property in the object named "decData". var decData = { labels: [], datasets: [ { fillColor: "rgba(151,187,205,0.5)", ...

Webpack 4 Failing to Properly Render Select Tag

I am encountering an issue with a basic select element that is not displaying correctly due to Webpack. The screenshot below illustrates the final rendered page source, where the closing tag for the select element has been incorrectly positioned before the ...

Disabling the default route on an ASP.NET MVC 5 controller: A step-by-step guide

Currently, I am in the process of developing a web application using ASP.NET MVC 5 that includes a personalized administration section housing all the essential app parameters. My primary objective is to have the flexibility to alter the name of this part ...

using spread operator to extract properties from API response objects

Currently undergoing a React/Next course, we recently had to retrieve data from an API that returns a list of objects containing information to populate the page. This task was accomplished using Next's getStaticProps method, passing the data to the ...

The text does not change in the input field even with the .value method

I'm encountering an issue where I want to use .value to set the text of an input field. However, after setting the value of the input field, the text disappears when clicked on. I would like to find a solution where the text does not disappear upon cl ...

The dynamic styles set by CSS/JavaScript are not being successfully implemented once the Ajax data is retrieved

I am currently coding in Zend Framework and facing an issue with the code provided below. Any suggestions for a solution would be appreciated. The following is my controller function that is being triggered via AJAX: public function fnshowinfoAction() { ...

Leverage Swift Decoder for extracting properties from JSON object list

Recently, I encountered a challenge while working with a JSON array that was generated using the following call: guard let json = (try? JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers)) as? [Any] els ...

Unable to retrieve the input value

I'm struggling to retrieve the input value from my form. Despite trying several solutions, I haven't been able to get any results. Here is the code for the form input: <input class="form-control" id="account_ya_price_list_url shop_key_input" ...

Searching for an element with a changing name using jQuery - Struggling with quotes

Looking to navigate my DOM based on the value of an option in a select box. The value of "searchkey" can vary based on user input, for example: searchkey = dell'anno searcheky = dell"anno These options, particularly the first one, can cause issues ...

Utilize the function specified in an external file

In my project, I have a typescript file named "menuTree.ts" which compiles to the following JavaScript code: define(["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Menu ...

Customizing the appearance of selection dropdown options in React

Is it possible to customize the styling of the choices in a React input dropdown? For instance, I am interested in creating an autocomplete dropdown that presents the options neatly arranged in columns. Essentially, I want to design a dropdown data grid t ...

Choose components identified by a dot

If I have a simple script that displays an element based on the option selected, how can I handle periods in the values? For instance: <select id="my-selector"> <option value="cat.meow">Cat</option> <option value="dog.bark"> ...