combine two JSON objects in Google Apps Script without using jQuery

Is there a way to combine two JSON objects in Google Spreadsheet script without using jQuery?

{"records":[{"id":28100988,"work_text_reviews_count":13,"average_rating":"3.10"},{"id":10280687,"work_text_reviews_count":80,"average_rating":"3.87"}]}

{"records":[{"id":16135639,"work_text_reviews_count":0,"average_rating":"0.00"},{"id":17978337,"work_text_reviews_count":2414,"average_rating":"3.76"{"id":360721218,"work_text_reviews_count":4924,"average_rating":"3.98"}]}

I need the resulting merged JSON object to be:

{"records":[{"id":28100988,"work_text_reviews_count":13,"average_rating":"3.10"},{"id":10280687,"work_text_reviews_count":80,"average_rating":"3.87"},{"id":16135639,"work_text_reviews_count":0,"average_rating":"0.00"},{"id":360721218,"work_text_reviews_count":4924,"average_rating":"3.98"}]}

I have tried various solutions in JavaScript all day, but I couldn't get them to work without any errors.

Answer №1

A simple solution would be to use the concat method:

const data1 = {
  "info": [{
    "id": 82347691,
    "quantity": 15,
    "price": "$12.99"
  }, {
    "id": 15789234,
    "quantity": 8,
    "price": "$17.50"
  }]
}

const data2 = {
  "info": [{
    "id": 54986123,
    "quantity": 0,
    "price": "$0.00"
  }, {
    "id": 32897546,
    "quantity": 152,
    "price": "$9.99"
  }, {
    "id": 78903241,
    "quantity": 246,
    "price": "$29.99"
  }]
}

const mergedData = data1.info.concat(data2.info);

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

Attempting to convert JSON date format in order to send it to a different system via a POST request in

My goal is to create a script that fetches project data from Insightly and posts it on 10000ft. The idea is to transfer any new projects created in one system to another system, both of which have the 'Project' concept. I am a beginner at this a ...

Drop items next to the specified keys. Vanilla JavaScript

I am trying to create a new array of objects without the gender field. Can you identify any mistakes in my code? let dataSets = [ { name: "Tim", gender: "male", age: 20 }, { name: "Sue", gender: "female", age: 25 }, { name: "Sam", gender: "m ...

Is there a way for me to retrieve the internal data from this array of errors within Google Custom Search?

I am currently working on a web application that utilizes Google Custom Search through REST. So far, everything is functioning properly. However, once I surpass the daily limit of queries allowed, I want to provide the user with relevant information. The J ...

Error: The SpringBoot API returned a SyntaxError because an unexpected token < was found at the beginning of the JSON response

I am currently following a tutorial on Spring Boot React CRUD operations which can be found here. However, I have encountered an issue when trying to fetch JSON data from the REST API and display it in my project. Despite following the steps outlined in th ...

Please provide a list of combinations of dictionaries containing lists and lists containing dictionaries from a JSON file through the terminal

How can I retrieve a JSON data structure from the terminal that consists of nested lists and dictionaries in any combination, similar to the following example: [{"type":"one", "wrapped":[Slow, Empty, {"type":"tw ...

Updating the JSON object wrapper name received from a WCF service method

In my WCF 3.5 application, I have created a method called TestMe with the following definition: [OperationContract] [WebInvoke(UriTemplate = "/Login", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseForma ...

Sending a JSON request using Swift 3

I am in need of posting JSON data that has the following structure: { "orders":[ {"id": 208, "quantity": 1 },{"id": 212, "quantity": 2},{"id": 202, "quantity": 5}, ...etc ],"HHStatus": "1 } Currently, I have a variable called orders : [ShoppingCart] = [] ...

Generating JSON output in PHP

I've been struggling to figure out why I can extract some parts of the JSON data but not others... Essentially, I am retrieving JSON from a URL (). In my PHP code (using Laravel5), I have the following: $url = 'https://public-crest.eveonline.co ...

How can we access a value within a deeply nested JSON object in Node.js when the key values in between are not

In the nested configuration object provided below, I am seeking to retrieve the value associated with key1, which in this case is "value1". It's important to note that while key1 remains static, the values for randomGeneratedNumber and randomGenerated ...

Exploring SharePoint's Json formatting capabilities

Seeking assistance with a challenge I am facing: within a SharePoint list, I have 3 columns. The first column indicates the number of days needed for a task to be completed (e.g. 5), the second calculates the date when the task will be due (today's da ...

Is there a way to parse a JSON string in Mono?

Do you know how to deserialize a JSON string in C# (Mono)? I'm looking for recommendations on a JSON library and guidance on installing it. I am currently working with Fedora 14. ...

Using Vue and PHP to parse a JSON string and display it as a table

I am currently facing a challenge in parsing a JSON string from my Laravel application to my Vue view. The format of the JSON string could be as follows: { "1":[ { "row":"Some text here on first column." }, { "row":"And more text. Second row ...

Using NodeJS to retrieve the mean price from the OPSkins pricelist

Is there a way to calculate the average price of every skin listed in this document? I'm wondering how one would go about using the dates and prices in order to determine the 60-day average price. My approach would involve extracting the data from t ...

Encountering a JSONDecodeError when sending a python dictionary via AJAX post

I have encountered an issue when passing a Python dictionary to a template and then using $.post to send it to a Django view. When I attempt to json.loads it in the view, I am getting a JSONDecodeError. Does anyone know how I can resolve this? //1. vars t ...

The lambda expression cannot be used with the operator '.'

I am attempting to craft a Linq lambda expression that will retrieve customers whose first or last names begin with specific letters. However, I am encountering an issue with the .select method where it is returning the error: The operator '.' c ...

Discovering particular segments in strings that include specific characters or symbols, and subsequently establishing a connection to those segments

My current data storage method involves using JSON strings in a database. However, due to the presence of quotation marks in the JSONs, the database converts all quotation marks to &quot;, making Unity unable to deserialize the JSON properly. This res ...

How to efficiently convert XML data and transform it into a flattened JSON format

My XML file has the following structure: <root> <foos> <foo> <id>1</id> <number>1245</number> </foo> <foo> <id>2</id> ...

Comparing the syntax of JSON to the switch statement in JavaScript

I recently came across a fascinating post on discussing an innovative approach to utilizing switch statements in JavaScript. Below, I've included a code snippet that demonstrates this alternative method. However, I'm puzzled as to why the alter ...

The conversion of java.lang.String to JSONObject is not possible

Can anyone help me with retrieving specific data from the server using this code? public String URL_ITEMS = "http://getdoctor.comlu.com/aa.php?name=Naveed"; private static final String TAG_FIXTURE = "checker"; private static final String TAG_MATCHID = "d ...

Highcharts real-time data not refreshing following modification of PHP variable

Currently, I have a live updating highchart implemented on a webpage named index.html. This highchart calls a PHP script called datatest.php to parse a CSV file, convert the data into JSON format, and then add it as a new point on the chart: $.ajax({ ...