Found 187 Articles for JSON

Explain how to extract value using JSONPath.

Debomita Bhattacharjee
Updated on 22-Nov-2021 09:59:08
We can use JsonPath in Rest Assured to extract value. This is done with the help of the jsonPath method (which is a part of the JsonPath class). After that, we need to use the get method and pass the key that we want to obtain from the JSON Response.We shall first send a GET request via Postman on an endpoint and observe the JSON response. Here, the keys are userId, id, title, and body.ExampleCode Implementationimport org.testng.annotations.Test; import static io.restassured.RestAssured.*; import io.restassured.RestAssured; import io.restassured.http.ContentType; import io.restassured.path.json.JsonPath; import io.restassured.response.Response; public class NewTest {    @Test    void getValueJsonPath() {   ... Read More

How to return a JSON object from a Python function in Tkinter?

Sarika Singh
Updated on 23-Nov-2022 07:50:53
JavaScript Object Notation, or JSON is a simple data format that is used to exchange data between many different languages. It is simple to read for people and simple for computers to parse. Python reads JSON text as a quoted-string that contains the value in each key-value mapping. Once parsed, it is accessible in Python as a dictionary object. JSON data can be encoded and decoded using the built-in package json in Python. You must first import the json library in order to work with files of the json type. Purposeco JSON Python to JSON conversion is done using serialization. ... Read More

Flattening a JSON object in JavaScript

AmitDiwan
Updated on 22-Feb-2021 10:20:27
Suppose, we have the following JSON object that may contain nesting upto any level −const obj = {    "one": 1,    "two": {       "three": 3    },    "four": {       "five": 5,       "six": {          "seven": 7       },       "eight": 8    },    "nine": 9 };We are required to write a JavaScript function that takes in one such nested JSON object and returns a new object that contains no nesting and maps the corresponding values to the keys using the dot ... Read More

Adding a unique id for each entry in JSON object in JavaScript

AmitDiwan
Updated on 25-Nov-2020 06:46:18
Suppose, we have an array described as follows −const arr = [    {       "Arts": [          {             "Performing arts": [                {                   "Music": [                      { "title": "Accompanying" },                      { "title": "Chamber music" },                      { "title": "Church music" },         ... Read More

Build tree array from JSON in JavaScript

AmitDiwan
Updated on 24-Nov-2020 10:25:34
Suppose, we have the following array in JavaScript −const arr = [{    "code": "2",    "name": "PENDING" }, {    "code": "2.2",    "name": "PENDING CHILDREN" }, {    "code": "2.2.01.01",    "name": "PENDING CHILDREN CHILDREN" }, {    "code": "2.2.01.02",    "name": "PENDING CHILDREN CHILDREN02" }, {    "code": "1",    "name": "ACTIVE" }, {    "code": "1.1",    "name": "ACTIVE CHILDREN" }, {    "code": "1.1.01",    "name": "ACTIVE CHILDREN CHILDREN" }];We are required to write a JavaScript function that takes in one such array. The function should build a tree structure from this array based on ... Read More

Convert JSON array into normal json in JavaScript

AmitDiwan
Updated on 24-Nov-2020 10:16:19
Suppose, we have a JSON array with key/value pair objects like this −const arr = [{    "key": "name",    "value": "john" }, {    "key": "number",    "value": "1234" }, {    "key": "price",    "value": [{       "item": [{          "item": [{             "key": "quantity",             "value": "20"          },          {             "key": "price",             "value": "200"          }]       }] ... Read More

JavaScript: create an array of JSON objects from linking two arrays

AmitDiwan
Updated on 23-Nov-2020 10:43:43
Suppose, we have two arrays like these −const meals = ["breakfast", "lunch", "dinner"]; const ingredients = [    ["eggs", "yogurt", "toast"],    ["falafel", "mushrooms", "fries"],    ["pasta", "cheese"] ];We are required to write a JavaScript function that takes in two such arrays and maps the subarrays in the second array to the corresponding strings of the first array.Therefore, the output for the above arrays should look like −const output = {    "breakfast" : ["eggs", "yogurt", "toast"],    "lunch": ["falafel", "mushrooms", "fries"],    "dinner": ["pasta", "cheese"] };ExampleThe code for this will be −const meals = ["breakfast", "lunch", "dinner"]; const ingredients ... Read More

Get value for key from nested JSON object in JavaScript

AmitDiwan
Updated on 23-Nov-2020 09:57:17
Suppose, we have a nested JSON object like this −const obj = {    "prop": [       {          "key": "FOO",          "value": "Foo is wonderfull, foo is great"       },       {          "key": "BAR",          "value": "Bar is bad, really bad"       }    ] };We are required to write a JavaScript function that takes in one such object as the first argument, and a key string as the second argument.Our function should then return the value for ... Read More

JSON group object in JavaScript

AmitDiwan
Updated on 23-Nov-2020 07:56:11
Suppose, we have an array of objects like this −const arr = [    { 'name': 'JON', 'flight':100, 'value': 12, type: 'uns' },    { 'name': 'JON', 'flight':100, 'value': 35, type: 'sch' },    { 'name': 'BILL', 'flight':200, 'value': 33, type: 'uns' },    { 'name': 'BILL', 'flight':200, 'value': 45, type: 'sch' } ];We are required to write a JavaScript function that takes in one such array of objects. The function should map remove the 'value' and 'type' keys from the objects and add their values as key value pairs to the respective objects.Therefore, the output for the above input ... Read More

Calculate average from JSON data based on multiple filters JavaScript

AmitDiwan
Updated on 23-Nov-2020 07:05:38
Suppose, we have an array of objects like this −const arr = [    { "SupplierName" : "John", "Category " : "A", "Points" : 3 },    { "SupplierName" : "John", "Category " : "A", "Points" : 11 },    { "SupplierName" : "John", "Category " : "A", "Points" : undefined },    { "SupplierName" : "John", "Category " : "B", "Points" : 2 },    { "SupplierName" : "John", "Category " : "B", "Points" : 6 },    { "SupplierName" : "Praveen", "Category " : "A", "Points" : 3 },    { "SupplierName" : "Praveen", "Category " : "A", ... Read More
1 2 3 4 5 6 7 ... 19 Next
Advertisements