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"
 }
]
asked Mar 27, 2020 at 4:22

1 Answer 1

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.

answered Apr 8, 2020 at 19:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.