Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
Get data from RichSnippet JSON and set the same string into other variable

I have this JSON generated from external (Reviews-io) script: https://widget.reviews.co.uk/rich-snippet/dist.js

    richSnippet({

        store: "www.storedigital.local",
        sku:"6647;6647_5;6647_4;6647_3;6647_11;6647_10;6647_2;6647_1;6647_9;6647_8;6647_7;6647_6",
        data:{
          "url": "store.stg.gsd.local/1/silla-replica-eames.html",
          "description": ``,
          "mpn": "6647",
          "offers" :[{
            "@type":"Offer",
            "availability": "http://schema.org/InStock",
            "price": "559",
            "priceCurrency": "MXN",
            "url": "https://store.stg.gsd.localx/1/silla-replica-eames.html",
            "priceValidUntil": "2022-05-26",
          }],
          "brand": {
           "@type": "Brand",
           "name": "Not Available",
         }
        }

    })

I need to get all the string of numbers in "sku", and then put them in another variable as same format (6647; 6647_1; 6647_2)

I try to get the numbers using this JS but doesn't works

var skucollection = JSON.parse(richSnippet, function (key, value) {
   if (key == "sku") {
     return new Sku(value);
    } else {
     return value;
    }
});

Can you help me check what I am doing wrong, to get this sku's value string, please?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JSON.parse is not too much? ,handle it as it is internally (a JSON indeed)

var richSnippet = {
  store: 'www.storedigital.local',
  sku: '6647;6647_5;6647_4;6647_3;6647_11;6647_10;6647_2;6647_1;6647_9;6647_8;6647_7;6647_6',
  algomas: [],
  data: {
    url: 'store.stg.gsd.local/1/silla-replica-eames.html',
    description: ``,
    mpn: '6647',
    offers: [
      {
        '@type': 'Offer',
        availability: 'http://schema.org/InStock',
        price: '559',
        priceCurrency: 'MXN',
        url: 'https://store.stg.gsd.localx/1/silla-replica-eames.html',
        priceValidUntil: '2022-05-26',
      },
    ],
    brand: {
      '@type': 'Brand',
      name: 'Not Available',
    },
  },
};
var test;
Object.keys(richSnippet).forEach((key) => {
  if (key == 'sku') {
    test = richSnippet[key];
  }
});

console.log('test', test);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda