Does anyone have any sample code on processing JSON data from a URL using Modified JavaScript Value in Java?

Could anyone provide some examples on how to handle returned Json data using Modified JavaScript Value? Here is the specific data I require from the json url:

{
"result": {
"data": [
{
"name": "page1",
"period": "dia",
"values": [
{
"value": 4,
"end_time": "2016-03-25"
},
{
"value": 2,
"end_time": "2016-03-26"
},
{
"value": 0,
"end_time": "2016-03-27"
}
],

},
{
"name": "page2",
"period": "dia",
"values": [
{
"value": 22,
"end_time": "2016-03-25"
},
{
"value": 30,
"end_time": "2016-03-26"
},
{
"value": 88,
"end_time": "2016-03-27"
}
],

} 

I need to create rows for this data. Regards, Santana, Marcos

Answer №1

Appreciate the assistance, you are correct, no need for JavaScript, just JSON. However, I encountered a problem. I am able to capture the names, but not the values and dates. Here is what I attempted: $ .. Date []. Name $ .. Date []. Values (the issue lies here, it loads three values (value, end_time) when only one is needed. I tried $ .value but it resulted in an error indicating multiple values.

I figured it out, I utilized a step select value, split fields, and Row Normaliser.

Thank you very much! Santana, Marcos

Answer №2

To optimize and speed up the process of populating rows with data, using JSON Input may be more effective. By specifying $..value and $..end_time in the Fields, you can easily generate rows.

If you prefer to use JavaScript (although JSON Input is recommended), below is a sample script to assist you:

var obj = JSON.parse(json);
datas = obj.result.data;
for (var i = 0; i < datas.length; i++) {
  var data = datas[i];
  for (var ii = 0; ii < data.values.length; ii++) {
    var value = data.values[ii];
    var row = createRowCopy(getOutputRowMeta().size());
    var idx = getInputRowMeta().size();
    row[idx++] = value.value;
    row[idx++] = value.end_time;
    putRow(row);
  }
}
trans_Status = SKIP_TRANSFORMATION;

Ensure that the output fields in the step include both "value" as string and "end_time" as string to capture the added values in the row.

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

Testing the Limits of CSS Hover

I'm having trouble figuring out how to implement this. When hovering, a yellow square/background should appear with an offset similar to the one in the image below. I am utilizing bootstrap for this project. Any assistance or guidance would be greatl ...

Easily toggle between various image source paths

In my current application, all HTML files have hardcoded relative image paths that point to a specific directory. For example: <img src="projectA/style/images/Preferences.png"/> Now, I am considering switching between two different project modes: & ...

Steps to successfully set up a React application without encountering any installation errors

Hey everyone, I've been trying to install React on my system for the past two days but keep encountering errors. Initially, I used the commands below to install the React app and it worked smoothly: 1. npm install -g create-react-app 2. create-react- ...

Using Selenium Webdriver with C# to dynamically expand a RadMenu Webelement in Javascript

I am currently working with Selenium WebDriver in C# and facing an issue with a RadMenu. My goal is to hover over the menu so that it expands a sub menu, where I can find a specific webelement to click. I have tried using JavaScript for this purpose, but u ...

My jQuery form is not functioning properly upon initialization

Let's take a look at this sample 'template' code: $(document).on("<EVENT>", "form", function() { $(this).find(".input input").each(function() { var required = $(this).attr("required"); var checkField = $(this).clos ...

Is there a specific requirement for importing a React component into a particular file?

I am facing an issue with my component and two JavaScript files: index.js and App.js. When I import the component into index.js, it displays correctly on the screen. However, when I import it into App.js, nothing appears on the screen. Here is the code fr ...

Incorporate this form created externally onto my website

I have been working on my website and I am looking to incorporate a form that opens up once the login button is clicked. This form was generated using an online form builder which provides an embed code for seamless integration onto websites. Below, you wi ...

Error: The process.binding feature is not supported in the current environment (browserify + selenium-webdriver)

Recently, I've been attempting to execute a Node.js code on the client side of my browser. To make my code compatible with browsers, I am using Browserify for conversion purposes. Below is the command I use for this transformation: browserify te ...

When utilizing a node.js TCP socket to receive and send modified data, the functionality only operates successfully on the initial attempt

I am attempting to create a node.js TCP socket that will receive data, modify it, and then send it back. I found a helpful example on Stack Overflow here: . The example works perfectly as is, but when I add my own code to send data back, it only works for ...

Struggling to decipher JSON using jQuery proved to be quite challenging

JSON object (parameters) "selectedShopeNumber":1765653589, "shopeNumbersForSelectedNames":[], "shopeNumbers":[1765653589, 660791222],"shopeNames":["Shope 1","Shope 2"] code var params = JSON.parse("[" + parameters + "]"); for (var i = 0; i < params.s ...

Can you switch out the double quotation marks for single quotation marks?

I've been struggling to replace every double quote in a string with a single quote. Here's what I have tried: const str = '1998: merger by absorption of Scac-Delmas-Vieljeux by Bolloré Technologies to become \"Bolloré.'; console ...

What was the reason for node js not functioning properly on identical paths?

When the search route is placed at the top, everything works fine. However, when it is placed at the end, the route that takes ID as a parameter keeps getting called repeatedly in Node. Why does this happen and how can it be resolved? router.get('/se ...

Adding div elements using checkbox switch

In this code snippet, my aim is to display costs based on checkbox selection and generate corresponding totals in the bottom row when the checkboxes are toggled. The goal is to allow users to choose relevant items and have the total cost calculated accordi ...

I am looking to manage the error handling service, and my next step is to intentionally insert a single error into my service and have it automated

Need help with error handling in my service. I want to manually insert a single error, but would like it to be done automatically instead. 'use strict'; angular.module('nexoolApp.errorservice', ['nexoolApp.config']) .servic ...

JSON AJAX script is failing to capture the data inputted into the form field

I am struggling to retrieve the $productid from the form. Not sure what I'm missing here. Any suggestions? The selected files do get uploaded, but not to the specified product folder, and there is no indication of success returned to index.php It&ap ...

Using JavaScript to extract data from a JSON-formatted URL

I am currently facing a challenge with parsing JSON data from a specific URL. Despite my efforts, I am unable to retrieve any information related to the "ask" and "bid" values from this JSON feed. The URL in question is . The structure of the JSON data is ...

JavaScript: Changing the names of all object keys

As a beginner, I am struggling to rename some objects in my key using a map function. Below is my current array: "platforms": [ { "id": 6, "name": "PC (Microsoft Windows)" }, { "id": 11, "na ...

Creating a case-insensitive path for pages in NextJS can be achieved by ensuring that all

I have a file named about.tsx under the pages folder. This means that the path for accessing the page is /about, allowing me to visit it through example.com/about. Strangely, attempting to access the same page via example.com/About results in a 404 error ...

The type '{ children: Element[]; }' does not include the properties 'location' and 'navigator' that are present in the 'RouterProps' type

Struggling to implement React Router V6 with TypeScript, encountering a type error when including Routes within the `<Router />` component. The error message indicates that the children property passed to the Router is of an incorrect type, despite u ...

Unable to execute a GET request using the Fetch API on Django REST Framework results in receiving an HTTP 304 error code

When attempting a GET request with the Fetch API (Node Fetch) module against a Django REST API, I am encountering a 304 error. I am unsure of how to resolve this issue as it seems to be related to requesting the same data repeatedly. Is there no way around ...