JSON attribute unreachable - "Cannot read property of undefined"

json attributes
json object
json parse undefined
json.parse null
json parse reviver
react json cannot read property of undefined
app json must include a json object cannot read property isdetached of null
react json parse

I am attempting to use the Wikipedia API to retrieve article titles and snippets of the article's text. But when I try to access those properties, I am getting the error "Cannot read property of undefined."

Here is my JSON response:

    "batchcomplete": "",
    "continue": {
        "gsroffset": 10,
        "continue": "gsroffset||"
    "query": {
        "pages": {
            "13834": {
                "pageid": 13834,
                "ns": 0,
                "title": "\"Hello, World!\" program",
                "index": 6,
                "extract": "<p>A <b>\"Hello, World!\" program</b> is a computer program that outputs or displays \"Hello, World!\" to a user. Being a very simple program in most programming languages, it is often used to illustrate the</p>..."
            "6710844": {
                "pageid": 6710844,
                "ns": 0,
                "title": "Hello",
                "index": 1,
                "extract": "<p><i><b>Hello</b></i> is a salutation or greeting in the English language. It is first attested in writing from 1826.</p>..."
            "1122016": {
                "pageid": 1122016,
                "ns": 0,
                "title": "Hello! (magazine)",
                "index": 7,
                "extract": "<p><i><b>Hello</b></i> (stylised as <i><b>HELLO!</b></i>) is a weekly magazine specialising in celebrity news and human-interest stories, published in the United Kingdom since 1988. It is the United Kingdom</p>..."

I have tried a couple different ways of writing the code. For example, this works (logs the pages as an object in the console):


But this returns the error I wrote above ("Cannot read property of undefined"):


Any suggestions on how to access the attributes "title" and "extract" would be appreciated. Thanks.

That's because pages is not an array; it's an object where the keys are the ids. So you need to do:


This will work. If you want the "first" page, for instance, then

let pages = response.query.pages;

Note that I'm not sure if the order of the keys in JS objects is guaranteed.

If you want to iterate over the pages, do

let pages = response.query.pages;
Object.keys(pages).forEach(id => {
    let page = pages[id];
    console.log(page.title, page.foo);

cannot access json object property returns undefined, I am accessing a key from json object but it returns undefined The initial value of undefined JSON attribute unreachable - “Cannot read property of undefined”� The MemberSerialization flag on this attribute specifies whether member serialization is opt-in (a member must have the JsonProperty or DataMember attribute to be serialized), opt-out (everything is serialized by default but can be ignored with the JsonIgnoreAttribute, Json.NET's default behavior) or fields (all public and private fields are serialized and properties are ignored).

Special Case: Working with Asynchronous Calls

Howdy fellow devs,

If you're checking out this thread because you're working with a framework like React, or some other framework that has you using a development server (e.g. using npm start or something similar), your dev server may be crashing when you try to do something like console.log(response.foo.bar) before it refreshes on data reload.

Specifically, my dev server was crashing with the Cannot read property 'bar' of undefined type message, and I was like, "what the heck is going on here!?". Solution: put that baby in a try/catch block:

try { 
  } catch (error) {

Why? If your App has a default state (even an empty array, for example), then it tries to console.log the response before the data has been received from the remote source, it will successfully log your empty state, but if you try to reference parts of the object you're expecting to receive from the remote source in your console.log or whatever else, the dev server will be trying to reference something not there on initial load and crash before it has a chance to reference it when it's actually received from the remote source via API or whatever.

Hope this helps someone!

SyntaxError: JSON.parse: bad parsing, JSON.parse('{"foo": 01}'); // SyntaxError: JSON.parse: expected ',' or '}' after property value // in object at line 1 column 2 of the JSON data� JSON objects are surrounded by curly braces {}. JSON objects are written in key/value pairs. Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null). Keys and values are separated by a colon. Each key/value pair is separated by a comma.

I'm not sure which language you're using to parse the JSON (looks like Javascript from console.log?) but the issue is that query.pages is a dictionary, not an array, so it can't be iterated by index, only by key.

So you want something like (pseudocode):

for (key in response.query.keys)

Tharper/1.4 backport unreachable disabled � Issue #5245 , -313,24 +321,33 @@ object Instance {. } } implicit val unreachableStrategyFormat: Format[UnreachableStrategy] = Json.format[ UnreachableStrategy]. implicit val� JSON property nc:PersonMiddleName contains two properties. rdf:value is a new property that only appears in JSON. Because JSON does not have attributes, the NIEM attribute nc:personNameInitialIndicator must be treated like a regular property. This requires the addition of a new property to hold the element’s original value, so a new name must

Error with deserializing json data into ienumerable, Your data has a property called "result" which is an array so you need a class that reflects that. Something like. Hide Copy Code. class MyData� The URL address is unreachable (IP address is unreachable, HTTP protocol is unreachable, firmware does not exist, server does not support Range request header, etc.) - 471: The operation failed and the firmware integrity check failed. The SHA256 checksum of the downloaded new firmware does not match the value of the request body’s sha256sum

TypeScript Programming with Visual Studio Code, Whether the variable/property type is callable (a function type) or not. VS Code provides IntelliSense for individual TypeScript files as well as TypeScript tsconfig. json projects. Removing unreachable code or unused imports; Declaring. You can use application settings to override host.json setting values without having to change the host.json file itself. This is helpful for scenarios where you need to configure or modify specific host.json settings for a specific environment. This also lets you change host.json settings without having to republish your project.

Class: Google::Apis::RunV1::ListDomainMappingsResponse , #unreachable ⇒ Array<String>. Locations that could not be Corresponds to the JSON property unreachable. Returns: (Array<String>)� Only one of COMMENT or ATTRIBUTE can be used in the same CREATE USER or ALTER USER statement. User comments and user attributes are stored together internally as a JSON object, with the comment text as the value of an element with the key comment.

  • To get an array of them: Object.keys(pages).map(id => pages[id])
  • "Note that I'm sure if the order of the keys in JS objects is guaranteed." Not with Object.keys or for-in, no. It is with Object.getOwnPropertyNames. (In this case, with Object.getOwnPropertyNames, it would be in numeric order ascending, as those keys fit the definition of an array index [yes, even though it's not an array].)
  • @RickHitchcock: Not with these keys, they fit the "array index" definition. Implementations have historically treated those differently from others.
  • Yes, I meant not sure updated above ;) Thanks for the insight.
  • Thanks for the answer and explanation!