0

How can I convert this json string into an array? I tried json_decode, but it returns null.

It was previously a .json file that i got its data using file_get_contents.

I also tried using an foreach loop butPHP libraries should provide an answer.

I also have look another related topics from stackoverflow without success.

Thanks!

{
   "1":{
      "entity_id":"1",
      "type_id":"simple",
      "sku":"dress_test",
      "status":"1",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"1.0000",
      "price":"1500.0000",
      "special_price":"1000.0000",
      "name":"Wedding dress",
      "url_key":"dress",
      "country_of_manufacture":"AO",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":"1",
      "news_from_date":"2012-03-21 00:00:00",
      "news_to_date":"2012-03-24 00:00:00",
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"White wedding dress"
   },
   "2":{
      "entity_id":"2",
      "type_id":"simple",
      "sku":"blazers",
      "status":"1",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"1.0000",
      "price":"200.0000",
      "special_price":"100.0000",
      "name":"Brazes",
      "url_key":"brazes",
      "country_of_manufacture":"AO",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":"1",
      "news_from_date":"2012-03-21 00:00:00",
      "news_to_date":"2012-03-24 00:00:00",
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"Blue brazes"
   },
   "3":{
      "entity_id":"3",
      "type_id":"simple",
      "sku":"black_sunglasses",
      "status":"1",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"0.2000",
      "price":"500.0000",
      "special_price":"300.0000",
      "name":"Sunglasses",
      "url_key":"sunglasses",
      "country_of_manufacture":"AR",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":null,
      "news_from_date":null,
      "news_to_date":null,
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"Black sunglasses"
   },
     "4":{
      "entity_id":"4",
      "type_id":"simple",
      "sku":"jacket",
      "status":"1",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"1.0000",
      "price":"800.0000",
      "name":"Jacket",
      "url_key":"jacket",
      "country_of_manufacture":"AO",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":"1",
      "news_from_date":"2012-03-21 00:00:00",
      "news_to_date":"2012-03-24 00:00:00",
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"Black jacket"
   },
     "5":{
      "entity_id":"5",
      "type_id":"simple",
      "sku":"green_shirts",
      "status":"0",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"1.0000",
      "price":"800.0000",
      "name":"Green shirts",
      "url_key":"green_shirts",
      "country_of_manufacture":"AO",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":"1",
      "news_from_date":"2012-03-21 00:00:00",
      "news_to_date":"2012-03-24 00:00:00",
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"Green shirts"
   },"6":{
      "entity_id":"6",
      "type_id":"simple",
      "sku":"orange_shirts",
      "status":"1",
      "visibility":"4",
      "tax_class_id":"2",
      "weight":"1.0000",
      "price":"800.0000",
      "name":"Orange shirts",
      "url_key":"orange",
      "country_of_manufacture":"AO",
      "msrp_display_actual_price_type":"2",
      "gift_message_available":"1",
      "news_from_date":"2012-03-21 00:00:00",
      "news_to_date":"2012-03-24 00:00:00",
      "special_from_date":"2012-03-21 00:00:00",
      "special_to_date":"2012-03-24 00:00:00",
      "description":"Orange shirts",
   }
}
2

1 Answer 1

3

Your last line of json has trailing comma(,), which is making your json invalid. Remove that comma from

"description":"Orange shirts",

The error from jsonlint

Error: Parse error on line 123:
...: "Orange shirts",   }}
----------------------^
Expecting 'STRING', got '}'

try to validate your json on https://jsonlint.com/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.