Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
JSON weird format access data

This is a JSON snip that is created in WooCommerce by a plugin that adds some metadata. I cannot change the formatting of this JSON because it is generated by a plugin. The problem is that the keys and the values are added in a weird way. I am iterating through the line_items and statically referencing this data which I don't want to do, I would like to know if there is a smart way to reference for example: "key": "_cpo_product_id", "value": "3572", if this was formatted correctly it would be: "_cpo_product_id": "3572" and not have "value" as a key, and it would be accessed by: foo.line_items[i]._cpo_product_id but with this configuration I am a bit lost, I am sure there is an easy way to find the value for a specific key. I am doing this on Google app scripts, but a solution in JavaScript should suffice.

JSON snip:

"line_items": [
        {
            "id": 749,
            "name": "Dune",
            "product_id": 3572,
            "variation_id": 0,
            "quantity": 1,
            "tax_class": "",
            "subtotal": "149.54",
            "subtotal_tax": "31.40",
            "total": "149.54",
            "total_tax": "31.40",
            "taxes": [
                {
                    "id": 24,
                    "total": "31.403148",
                    "subtotal": "31.403148"
                }
            ],
            "meta_data": [
                {
                    "id": 11919,
                    "key": "_cpo_product_id",
                    "value": "3572",
                    "display_key": "_cpo_product_id",
                    "display_value": "3572"
                },
                {
                    "id": 11920,
                    "key": "_add-to-cart",
                    "value": "3572",
                    "display_key": "_add-to-cart",
                    "display_value": "3572"
                },
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!