Exploring methods to identify the initial value for JSON decoding in Swift

I have been working on decoding a JSON tree in Swift and below is an example of what the JSON tree looks like:

{
    "_type" = News;
    queryContext =     {
        originalQuery = "";
    };
    readLink = "https://api.cognitive.microsoft.com/api/v7/news/search?q=";
    value =     (
                {
            ampUrl = "https://www.msn.com/en-us/news/us/its-no-different-from-new-york-urban-centers-nationwide-gird-for-catastrophic-virus-outbreak/amp/ar-BB11QzZ6?li=BBnb7Kz";
            category = Health;
            datePublished = "2020-03-28T18:36:05.0000000Z";
            description = "In Chicago, the Army Corps of Engineers was preparing to erect 2,500 patient quarters throughout three of the cavernous halls at McCormick Place, the largest convention center in North America. In Detroit, a major hospital system was readying a letter for patients and their families outlining how scarce ventilators would be allocated, saying ...";
            headline = 1;
            image =             {
                thumbnail =                 {
                    contentUrl = "https://www.bing.com/th?id=ON.0EDDB46C77D1689214EC5B7940C23A91&pid=News";
                    height = 367;
                    width = 700;
                };
            };
            name = "\U2018It\U2019s no different from New York\U2019: Urban centers nationwide gird for catastrophic virus outbreak";
            provider =             (
                                {
                    "_type" = Organization;
                    image =                     {
                        thumbnail =                         {
                            contentUrl = "https://www.bing.com/th?id=AR_04bc0c1c424cf64dec14a2982f0360ef&pid=news";
                        };
                    };
                    name = "The Washington Post on MSN.com";
                }
            );

The struct I am using for Decoding the data is as follows:

struct Articles: Decodable {
    let values: [String: String]
    let name: String
}

However, when I try to decode the data, my terminal is indicating that the value of "name" does not exist. Do you think the data I need is under 'value' or could it be somewhere else?

Answer №1

Revise your Structure like this for better results:

structure Articles: Decodable {
    let hyperLink: String
    let data: [DataPoints]
}

structure DataPoints: Decodable {
    let summary: String
    let header: String
}

header can be found within the data list.

Which header are you attempting to decipher? There is another one located in the Organization list.

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

Updating specific keys or attributes within a JSON column in Postgres using a form

Struggling to update a JSON column in a rails model. An issue I'm facing involves an OrderItem model with an :options column using the postgres json datatype. When attempting to update only two attributes within that JSON column through a form, the ...

Using React to visualize data from Node.js in Chart.js

My Node.js application fetches a JSON object from a MySQL database and I want to display it in real-time using Chart.js and React. Here is the code snippet for fetching the JSON data from the MySQL database (script.js): const mysql=require('mysql&apo ...

I am currently working with a for loop within an object in JavaScript, but there seems to be a problem with one

Here is a function called validator: import validator from "validator"; import isEmpty from "is-empty"; export default function validate(data) { const errors = {}; for (const property in data) { console.log(property); //< ...

Ways to retrieve information from a database using a specific ID stored in a JSON format

My device has generated a JSON file with an ID that needs to be deserialized. I want to use this ID as a parameter to select data from my database. Can anyone assist me with this? ...

Searching for values within a JSON file can be accomplished by using the appropriate tools

I'm trying to extract the value of "ID" which is set to "SGML" from the following JSON data. I am currently using Gson to parse the JSON file. How can I efficiently locate and retrieve this information? { "glossary": { "title": "example g ...

Using Java classes for the deserialization of Json in Android applications

Using asp.net web api on the server and android on the client, I am making a request from android to the web api and receiving a JSON string. However, when I try to assign this JSON string to a Java object using Gson, an exception is thrown. Here is my cod ...

Vulnerability protection against AngularJS JSON is not removed

I am currently working on an Angular app that communicates with an API. The JSON responses from the API are prefixed with )]}', as recommended in Angular's official documentation. The issue I am facing is that my browser seems to try decoding th ...

When attempting to send JSON data, I encountered an issue: Unable to read JObject from JsonReader. The error occurred at Path '', line 3, position 1

An error occurred while attempting to read JObject from JsonReader. Path '', line 3, position 1. Do you have any insights as to why this issue is happening? The code I am using works when sent to parse, but when trying to send it to my own domai ...

Retrieving the value of an item within a string array using VB.NET

Here is the code snippet I am working with: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim JsonSub As String = "{""subdomain01"":[""21"",""subdomain01"",""4""],""subdomain02"":[""22"","" ...

Using JQ for parsing deeply nested arrays

Having trouble extracting data from a JSON file: { "operations": [ { "operationName": "GetValue", "batch_size": "2", "orders": [ { "clientId": "7836", "validation_time": { "place": "136", ...

Using a foreach loop to iterate over each tag in a C# object and then utilizing Entity Framework to insert them into

An illustration of the Input JSON Format appears as follows: { Reservations: [ { FacilityReservationID:"....", FacilityID:"....", Description:"...." ...

Utilizing Javascript to Extract Data from Twitter Json Files

Can someone provide assistance with parsing JSON feed text retrieved from Twitter? I am looking to access and apply style tags to elements like the link, created date, and other information. Any tips on how I can achieve this task successfully would be g ...

Ensuring Data Consistency: Using TypeScript to Strongly Type Arrays with Mixed Variable Types

I have a JSON array that may contain objects of two types, defined by IPerson and ICompany. [ { "Name" : "Bob", "Age" : 50, "Address": "New Jersey"}, { "Name" : "AB ...

Rapidly process likes from all Facebook friends by making multiple JSON requests

I had an interesting idea to develop a program that could analyze the likes of a person's Facebook friends. While there are likely other applications out there claiming to find your "Perfect Match" based on this data, I wanted to create something uniq ...

Storing JSON string values in String parameters: A beginner's guide

Does anyone have experience with storing JSON strings from Oracle MCS CustomAPI responses in separate String parameters to create data controls? { "Header": { "MessageID": "uE60F40847D", "ReplyTo": { "Address": "http:2005/08/addressing/ano ...

Functionalities for retrieving nested JSON data structures

Currently, I am seeking a solution to implement a sequence where a .getJSON call triggers another function which then initiates another .getJSON call. I am repeatedly invoking a JSON method on my Controller and aiming to terminate this repetitive process ...

Decoding JSON data in jQuery using JSONP

Here is a JSON file: { "weather": [ { "location": "G", "temp": "9" }, { "location": "L", "temp": "6" }, { "location": "W", "temp": "10" } ] } This is the script I used: <script ...

What is the best way to retrieve the name of a unique JSON field and find the value of a deeply nested child field in Golang?

I am working with a json file that has the following structure: { "links": { "uniqueurl_1": { "a": { "b": [ "stuff" ], "I": { "want": { "to": "morestuff", "go": { ...

In JavaScript, when all values are false in an object, the object's value should be set to False

My task involves working with a JSON data object that contains multiple key-value pairs. I need to determine whether at least one value is false and set another variable to "false" accordingly. Here is the JSON data that I am handling: var objectVal = re ...

Trouble displaying data with Angular 6 JSON object pipe

Having an issue with displaying tasks from a MongoDB project schema in HTML. The tasks are stored in a nested array and I want to show the task name and description. Here's the code: <div class="card-body"> {{project.taskName | json}} </ ...