-1

I am quite new to working with JSON objects.

I am trying to drill down to the property value: Key Account Manager in my JSON object

I think it will be something like:

${ JSON.parse(post.localization).values['locale'] }

JSON object:

[
    {
    jobId: 57,
    applyUrl: {
    localization: [
    {
    locale: "en-GB",
    value: "https://ohly-v2....."
    },
    {
    locale: "de-DE",
    value: "https://ohly-v2...."
    }
    ]
    },
    adUrl: {
    localization: [
    {
    locale: "en-GB",
    value: "https://ohly-v2...."
    },
    {
    locale: "de-DE",
    value: "https://ohly-v2...."
    }
    ]
    },
    timeZone: "Europe/Copenhagen",
    mediaId: "cf7b7c03-83fa-499a-95aa-f73a0641e8ae",
    advertisements: [
    {
    default: true,
    title: {
    localization: [
    {
    locale: "de-DE",
    value: "Key Account Manager"
    },
    {
    locale: "en-GB",
    value: "Key Account Manager"
    }
    ]
    },
    content: {
    localization: [
    {
    locale: "de-DE",
    value: "dfhsehrwe5hwejhwrtws"
    }
    }
]

Is their a website where I can copy and paste my data structure in and it will aid in drilling down to bits I need?

BennKingy
  • 1,265
  • 1
  • 18
  • 43

1 Answers1

-1
  1. Paste into http://json.parser.online.fr/ and fix the errors, In your case missing quotes and end brackets

  2. Paste the fixed object into the [<>] snippet editor here and click TIDY

  3. Scan the resulting data from left to right

jsObject[0]
  .advertisements[0]
    .title
      .localization
        .forEach(loc => console.log(loc.locale,loc.value))

The last Key Account Manager:

jsObject[0].advertisements[0].title.localization[1].value

var jsObject = [{
  "jobId": 57,
  "applyUrl": {
    "localization": [{
        "locale": "en-GB",
        "value": "https://ohly-v2....."
      },
      {
        "locale": "de-DE",
        "value": "https://ohly-v2...."
      }
    ]
  },
  "adUrl": {
    "localization": [{
        "locale": "en-GB",
        "value": "https://ohly-v2...."
      },
      {
        "locale": "de-DE",
        "value": "https://ohly-v2...."
      }
    ]
  },
  "timeZone": "Europe/Copenhagen",
  "mediaId": "cf7b7c03-83fa-499a-95aa-f73a0641e8ae",
  "advertisements": [{
    "default": true,
    "title": {
      "localization": [{
          "locale": "de-DE",
          "value": "Key Account Manager"
        },
        {
          "locale": "en-GB",
          "value": "Key Account Manager"
        }
      ]
    },
    "content": {
      "localization": [{
        "locale": "de-DE",
        "value": "dfhsehrwe5hwejhwrtws"
      }]
    }
  }]
}]

jsObject[0].advertisements[0].title.localization.forEach(loc => console.log(loc.locale,loc.value))

// just the last
console.log(jsObject[0].advertisements[0].title.localization[1].value)
mplungjan
  • 169,008
  • 28
  • 173
  • 236