Why am I unable to retrieve the property from the JSON file?

Below is the provided JSON data:

data = {
    "company_name": "חברה לדוגמה",
    "audit_period_begin": "01/01/2021",
    "audit_period_end": "31/12/2021",
    "reports": [
        {
            "type": {
                "he": "מאזן",
                "en": "Balance Sheets"
            },
            "fin_statement": "BS",
            "sections": [
                {
                    "section_name": {
                        "he": "נכסים שוטפים",
                        "en": "Current Assets"
                    },
                    "totals": {
                        "2020": {
                            "final_total_local": 100000,
                            "final_total_foreign": 0
                        },
                        "2021": {
                            "final_total_local": 110000,
                            "final_total_foreign": 0
                        }
                    },
                    "subsections": [
                        {......(the rest is irrelevant)

My objective is to access the following in the code snippet:

data.reports[0].sections[0]['totals']

However, I'm encountering a specific error message:

Element implicitly has an 'any' type because expression of type '"totals"' can't be used to index type 

This results in the inability to read the property. Can you clarify why?

Answer №1

Once you have successfully obtained the

data.reports[0].sections[0].totals
, it seems like you are treating it as an array when it is actually an object. You may want to try accessing the data using
data.reports[0].sections[0]['totals']["2020"]
instead of
data.reports[0].sections[0]['totals'][2020]
. Keep in mind that this suggestion is based on limited information provided.

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

Inject JSON data into a jQuery plugin

Currently, I am exploring how to input settings into an animation plugin in the format below (I understand it may not be user-friendly to require users to tinker with settings like this, but a GUI will be developed alongside it): $('#animationContain ...

The Event Typing System

I am currently in the process of setting up a typed event system and have encountered an issue that I need help with: enum Event { ItemCreated = "item-created", UserUpdated = "user-updated", } export interface Events { [Event.Ite ...

Is there a way to validate user input in the front-end using my ANTLR grammar implemented in the back-end?

I have implemented a system using the ANTLR parser in Java for the backend of our software (frontend in Angular 2+). While the connection between the frontend inputs and backend logic is working well, there is a concern that users may input data with typos ...

tips for iterating through a json string

When retrieving data from PHP, I structure the return like this: $return['fillable'] = [ 'field_one', 'field_two', 'field_three', 'field_four', 'field_five', ]; $json = json_ ...

"Exploring the power of AngularJS: Combining server side validation with dynamic client

Currently, I am trying to grasp the concept of declaring a form properly. My understanding is that one should simply declare the form in HTML and include ng-model directives like this: ng-model="item.name" When it comes to sending data to the server, I b ...

Determine if a condition is met in Firebase Observable using scan() and return the

Within Firebase, I have objects for articles structured like this: articles UNIQUE_KEY title: 'Some title' validUntil: '2017-09-29T21:00:00.000Z' UNIQUE_KEY title: 'Other title' validUntil: '2017-10-29T21:00:00 ...

How to retrieve a JSON item without knowing the name of the parent key

When requesting JSON from Wikipedia's API, the URL is: http://en.wikipedia.org/w/api.php?action=query&prop=description&titles=WTO&prop=extracts&exsentences&explaintext&format=json This is how the response is structured: { ...

Trouble with the SetDateFormat() method in ObjectMapper

In my current project, I have utilized the ObjectMapper to convert an object into a Json String. The object contains date fields that need to be formatted accordingly. However, despite using the code snippet below, the formatting is not as expected. Below ...

Flex-Layout in Angular - The Ultimate Combination

Recently, I decided to delve into Angular and the Flex-Layout framework. After installing flex-layout through npm, I proceeded to import it in my app.module.ts file like so: import { FlexLayoutModule } from '@angular/flex-layout'; imports: [ Fl ...

Combining types: unable to utilize the second optional type within a for loop

I am facing an issue while looping through an array due to the union type. I am wondering what I have overlooked in the code below that is causing Visual Studio Code to not recognize the second optional type for that specific array. class Menu { // name ...

How can you modify the starting point of data in jQuery flot?

Currently using Flot to create a graph displaying clicks per minute within the first 60 minutes of short URLs generated at . The graph currently displays data from minute 0 to minute 59. My query is about adjusting the data to start at 1 and end at 59, wh ...

Issue with Play framework's JSON output functionality

My current situation involves a straightforward action that outputs a JSON object string as shown here: Ok(toJson(Map( "results" -> result_lists ))) Initially, this function performs as expected. However, when I attempt the following: Ok(toJson(Map ...

An unusual problem encountered while working with NextJS and NextAuth

In my NextJS authentication setup, I am using a custom token provider/service as outlined in this guide. The code structure is as follows: async function refreshAccessToken(authToken: AuthToken) { try { const tokenResponse = await AuthApi.refre ...

Is there a way to manage null JSON data?

Upon receiving JSON data from the server, I proceed to send a post request for deletion. If the JSON data matches this format, there are no issues and I can easily parse it: {"tables":[{"id":"1","number":"4"},{"id":"2","number":"1"},{"id":"3","number":"2 ...

The Android application created on Android Studio is experiencing crashes due to issues with org.json.XML

I'm encountering difficulties with a small Android application I developed using Android Studio. My goal is to extract JSON from an XML string by utilizing org.json.XML within a button click routine. Unfortunately, when running the app in debug mode, ...

Tips for extracting HTML content from JSON data as valid HTML code

I am attempting to extract HTML content from a JSON object response.indexText, which has been validated with JSONLint. { "indexText": "<div id=\"content-home\"><h1> Hello World! <\/h1> <p>Some text.<\/p> ...

Python Find File Results in Empty Set []

When attempting to search a JSON file for the username, I am encountering an issue where instead of retrieving "tom123," it is only returning []. Here is the content of the JSON file: [{"id":"001788fffe48cbdb","username":"tom123"}] Below is the code sni ...

A step-by-step guide on using JSON to map a property from an object

Working on a web application with the play framework, here is the class I am using: public class Project{ String name; Image image; } This is the image class: public class Image{ String path; String name; int x; int y; } I am trying to se ...

Utilizing shared components across a Next.js application within a monorepo

Utilizing a monorepo to share types, DTOs, and other isomorphic app components from backend services (Nest.js) within the same mono repo has presented some challenges for me. In my setup, both the next.js app and nest.js app (which itself is a nest.js mono ...

Having difficulty retrieving query or JSON keys from the Prometheus HTTP Server

I am trying to retrieve a specific metric called zcash_difficulty_gauge from the Prometheus HTTP Server, but I am encountering two issues: i) JSON data is not available ii) The request URL does not return just the desired metric, instead it returns the ent ...