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

102
Visualizações
JavaScript - Modify localstorage json

I have the following Json, in the browser's localstorage, I want to know if there is a way to take it and modify it with JavaScript.

The json you are seeing is modified to make it easier to understand the information, but it grows more than 22 thousand lines and exponentially due to the values ​​of the variable called pricelist.

What I want to do is :

  1. grab the json from localstorage.

  2. make a method that goes through all the json and when it finds the variable "pricelist" delete the content that has "items_ids" and "items"

  3. reload the json to the same key

ANNOTATIONS: -the variable lines can be empty. -the variable pricelist can be false.

Thank you very much for your attention and your comments.

[
{
   "id":"00027-008-0001",
   "data":{
      "lines":[
        [
            0,
            0,
            {
               "product_id":23603,
               "pricelist":{
                  "id":10,
                  "item_ids":[
                     27069,
                     26894
                  ],
                  "items":[
                    {
                        "id":20044,
                        "product_tmpl_id":[
                           13142,
                           "[DNCM1LT] DESENGRASANTE NARANJA CITRUSMAX 1 LT"
                        ]
                    }
                    ]
                },
                "uom_id":[
                    1
                ]
            }
        ],
        [
            0,
            0,
            {
               "product_id":23666,
               "pricelist":false,
                "uom_id":[
                    1
                ]
            }
        ]
        ],
        "pos_session_id":27
    }
},
{
    "id":"00027-008-0002",
    "data":{
       "lines":[
          [
             0,
             0,
             {
                "product_id":23655,
                "pricelist":false,
                 "uom_id":[
                     1
                 ]
             }
         ]
         ],
         "pos_session_id":27
     }
 },
{
    "id":"00027-008-0003",
    "data":{
        "lines":[
        
        ],
        "pos_session_id":27
    }
}]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can do it like the following:

let obj = JSON.parse(localStorage.get("item"));
obj.key = "value";
localStorage.set("item", JSON.stringify(obj));
about 4 years ago · Juan Pablo Isaza Relatório

0

Checkout the window.localStorage

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

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