Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:30:18+00:00 2026-05-27T13:30:18+00:00

I have the following JSON: { Files: { Lines: { 198: { firstline: sometext

  • 0

I have the following JSON:

{
    "Files": {
             "Lines": {
                    "198": {
                           "firstline": "sometext"
                    }
             }
    }
}

and the value “198” is dynamic and changes. How can I access the “firstline” property easily without knowing “198” in the following code:

var schema = JSON.parse(fileContents); 
console.log(schema.Files.Lines.????.firstline);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:30:19+00:00Added an answer on May 27, 2026 at 1:30 pm

    A few lines will do it:

    var obj = JSON.parse(your_json);
    var lines = obj.Files.Lines;
    var keys = Object.keys(lines);
    var keyICareAbout = keys[0];
    var info  = lines[keyICareAbout];
    

    Note: This solution relies on some newer javascript features. For JSON to work in all browsers, you will need Douglas Crockford’s json2.js from here. For Object.keys to work in all browsers, use this shim from Mozilla’s JS docuentation:

    if(!Object.keys) Object.keys = function(o){
     if (o !== Object(o))
          throw new TypeError('Object.keys called on non-object');
     var ret=[],p;
     for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);
     return ret;
    }
    

    Edit: Try this jsfiddle. Now updated with cross browser compatability measures and accessing data dynamically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following json code file named: sections.json { section1: { priority: 1,
I have a configuration file in the following JSON format: { key1: value1, key2:
I have the following JSON structure: [{ id:10, class: child-of-9 }, { id: 11,
I have the following JSON object: { response: { status: 200 }, messages: [
I have the following Json : {\doc\:{\info\:{\allowDistribution\:\true\,\allowSearch\:\true\,\calaisRequestID\:\67a02f61-7e45-cfc4-1276-e123c5f7422f\,\externalID\:\\,\id\:\ http://id.opencalais.com/dBo1YRiQeqS-kfO-m9UeWA \,\docId\:\ http://d.opencalais.com/dochash-1/8edabb36-eece-3f67-b187-ab64cd885ecb \,\document\:\What type of music
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I have an json output of the following (ignore the escape characters) {\sEcho\:1,\iTotalRecords\:10,\iTotalDisplayRecords\:10,\aaData\:[{\Job\:\developer\,\Name\:\kurt\},{\Job\:\plumber\,\Name\:\john\}]} which
I have follwing JSON: {mykey:[{name:Jak,interests:movies}]} and following opensocial app code: <script type=text/os-template require=mykey> <ul>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.