0

While i am trying to get order custom attribute data using rest api it's coming as string. But magento returning all other data as JSON. Does anyone have any idea how to make this look like json?

Actual result:

extra_fee": [
        "{\"code\":\"mp_extra_fee_rule_2_auto\",\"title\":\"Credit Card Surcharge\",\"label\":\"Credit Card Surcharge\",\"value\":17.22,\"value_excl_tax\":17.22,\"value_incl_tax\":17.22,\"base_value\":17.22,\"base_value_incl_tax\":17.22,\"rf\":\"0\",\"display_area\":\"3\",\"apply_type\":\"1\",\"rule_label\":\"Credit Card Surcharge\"}",
        "{\"code\":\"mp_extra_fee_rule_3_option_0\",\"title\":\"110\",\"label\":\"110\",\"value\":1148,\"base_value\":1148,\"value_incl_tax\":1148,\"value_excl_tax\":1148,\"base_value_incl_tax\":1148,\"rf\":\"0\",\"display_area\":\"3\",\"apply_type\":\"2\",\"rule_label\":\"Manage Titles Discount\"}"
    ]

Expected Result:

extra_fee": [
    {
    "code":"mp_extra_fee_rule_2_auto",
    "title":"Credit Card Surcharge",
    "label":"Credit Card Surcharge",
    "value":17.22,
    "value_excl_tax":17.22,
    "value_incl_tax":17.22,
    "base_value":17.22,
    "base_value_incl_tax":17.22,
    "rf":"0",
    "display_area":"3",
    "apply_type":"1",
    "rule_label":"Credit Card Surcharge"
    },
    {
    "code":"mp_extra_fee_rule_3_option_0",
    "title":"110",
    "label":"110",
    "value":1148,
    "base_value":1148,
    "value_incl_tax":1148,
    "value_excl_tax":1148,
    "base_value_incl_tax":1148,
    "rf":"0",
    "display_area":"3",
    "apply_type":"2",
    "rule_label":"Manage Titles Discount"
    }
]
0

Custom fields often have values containing encoded JSON because the Magento code itself doesn't try to understand how the custom fields function.

In your example above, if you iterate the values in the extra_fee array and parse them as JSON, you'll get usable objects.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.