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

Having an issue with the return function in a jQuery $.ajax call

I am currently working with a $.ajax call that is structured like this: <script type="text/javascript"> $(document).ready(function () { $('#add_com_frm').submit(function (e) { e.preventDefault(); var $b ...

Loop through each HTML element and store it in a JavaScript array

I currently have a webpage with 3 select buttons named "Season". I am trying to figure out which buttons are selected and receive their values as an array on my webpage. Below is the code I am using: var season_array = $.each($(form).children("input.sele ...

The absence of FormData.entries in submit is a limitation of the Vue framework

I recently created a Vue-App that consists of a simple form with just one <input name"surname"> and a <button type="submit">. The use case is to input "myname" and submit the form. However, when I initialize new FormData( ...

Avoiding memory leaks in Reactjs when canceling a subscription in an async promise

My React component features an async request that dispatches an action to the Redux store from within the useEffect hook: const fetchData = async () => { setIsLoading(true); try { await dispatch(dataActions.fetchData(use ...

Is there a way to input the Sno data into the database in ascending order?

function table_insert(lease_ids){ var lease_id=lease_ids+1; var table = document.getElementById('table_data123'), rows = table.getElementsByTagName('tr'), i, j, cells, customerId; for (i = 0, j = rows.le ...

Enable the execution of a function only once a specific period of time has elapsed

Here's the scenario I'm dealing with: In a fun group chat with my friends, I created a giphy bot that responds to /giphy [terms] messages by posting the top result for those terms. However, my friends started abusing it by spamming the chat. To ...

Filter object in Angular to remove empty values

Below are the specific data sets: $scope.icons = [{ "id": 1, "bonuses": [ { "id": 1, "name": "Rob", "amount": 10, "foreman": 1, "percA": 1, "percB": 0 }, { "id": 2, "name": "Mark", "amount": 20, "foreman": 1, "percA": 1, "percB": 0 }, ] }, { ...

Encountering an issue with an Uncaught SyntaxError: Unexpected identifier

I've been attempting to send data through ajax but keep encountering errors. Here's the code I have: jQuery.ajax({ url : '', type: 'POST', ...

Replace all occurrences of a specific string throughout a extensive document in Node.js

I'm facing a challenge with handling large files in memory. I need to go through each line, replace any double quotes found, and update the file itself. Currently, I am reading the file line by line, storing it in an array, and then overwriting the sa ...

Looking for a way to sort through data using the current time as a filter

In my possession is an object presented below: const user = { id: 3, name: "Clark Kent", mobileNumber: "1234567892", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385d40595548545d674d4b ...

Execute a script upon page load

Is there a way to trigger a script tag <script> immediately upon the website loading? I've experimented with various codes, but haven't found one that meets my needs. ...

Discover a demonstration showcasing login and registration functionalities by utilizing Flask, SQLAlchemy, Angular, and JSON

Hello everyone, I am new to Flask, SQLAlchemy, Angular, and JSON. Despite being a beginner in these technologies, I am working on building an application that utilizes them. Can anyone kindly share a small demo of a login and registration page with me or ...

What's the best way to organize a list while implementing List Rendering in VueJS?

Currently, I am working on List Rendering in Vue2. The list is rendering correctly, but it appears ordered based on the data arrangement in the array. For better organization, I need to sort each item alphabetically by title. However, I am facing difficult ...

Using node.js to make an HTTP request and parse JSON data with the

I am currently working on developing a web application using node.js that needs to interact with a PHP API. My goal is to request a JSON object from the PHP API, which I can then use in one of my .ejs templates. Below is the code snippet for my node.js im ...

NPM installation encounters enigmatic error stating "Unforeseen symbol in JSON"

The intentional double space in the subject between "token" and "in" is crucial (note: SO has removed the double space!). When opening the NPM log file in nano, a hint is revealed; 3911 verbose stack SyntaxError: Unexpected token ^@ in JSON at position 17 ...

Exploring Best Practices for Coding in node.js

Method 1: Constructor and Prototype Objects function Database(url) { this.url = url; } Database.prototype.info = function (callback) { http.get(this.url + '/info', callback); }; Method 2: Closures Approach function Database(url) { ...

Transforming flat JSON into nested JSON with multiple arrays can be achieved using the Jolt transform

Struggling to create a JOLT transformation for converting flat JSON to nested JSON? Need help transforming the JSON structure using a JOLT spec? Visit to test your transformations. Input : [ { "container_id": "a", "carr ...

Maximizing Efficiency: Utilizing a Single jQuery Function to Retrieve Specific Values

I have a webpage with select menus for choosing user type, minimum age, and maximum age. I want to select options and send values as an object array to ajax. Initially, the getAjax function is working when the page loads. However, it stops working when I c ...

Sort through a collection of data using a specific keyword

Upon receiving a list of fonts from the googlefontsapi, I have created a function to filter the font based on a specific key value. public function filterFont() { $key = $this->request('key'); $url = "https://www.googleapis.com/webfo ...

The ng-repeat function is currently disabled and not displaying any data from the JSON object

I am currently facing an issue where the ng-repeat Directive in my code is getting commented out and not displaying the results of the JSON object. I have verified that the object is being properly passed to "this.paises2" using the toSource() method, and ...