-1

Here is ths json I'm using :

{
    "data": [{
        "Contact_Name": {
            "id": "1884053000034678068"
        },
        "Subject": "1 - XKBKNABJK",
        "Status": "Sans Impact Stock",
        "Entity": "",
        "Etat": "CM - Annul\u00e9",
        "Invoice_Date": "2017-11-21",
        "Discount": 0.000000,
        "Tax": ["TVA"],
        "Total_HT": "55.000000",
        "Total_TVA": 0,
        "Methode_de_paiement": "Payment by check",
        "ID_Lip": "1",
        "Origine": "CM",
        "Type_de_Facture": "Solde",
        "Transporteur": "My carrier",
        "Reference_Colis": "",
        "Billing_Street": "16, Main street",
        "Compl_ment_Facturation": "2nd floor",
        "Billing_City": "Miami",
        "Billing_Country": "\u00c9tats-Unis",
        "Billing_Code": "33133",
        "Shipping_Street": "16, Main street",
        "Compl_ment_Livraison": "2nd floor",
        "Shipping_City": "Miami",
        "Shipping_Country": "\u00c9tats-Unis",
        "Shipping_Code": "33133",
        "Product_Details": [{
            "product": {
                "id": "1884053000030235273"
            },
            "Product_Name": Blouse - Color: White,
             Size: M,
            "list_price": 22.5,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
                "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }, {
            "product": {
                "id": "1884053000030235273"
            },
            "Product_Name": Printed Dress - Color: Orange,
            Size: S,
            "list_price": 21.67,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
            "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }, {
            "product": {
                "id": "1884053000012868763"
            }, 
            "list_price": 1.67,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
            "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }],
        "Adjustment": 0,
        "Montant_TPH": 0,
        "TVA_sur_DEEE_TPH": "0",
        "Taxes_DEEE_TPH": "TPH",
        "Frais_de_port_HT": "2.000000",
        "Frais_de_port_TTC": "2.000000",
        "Nb_produits": 3,
        "Quantite_totale": 3
    }],
    "duplicate_check_fields": ["ID_Lip"],
    "trigger": []
}

But when I use the json_encode() function it doesn't return me an object json but simply an empty array, and I don't see any syntax error in the code too. I don't know if it's really a syntax error or something else.. Can someone helps me know what/where is the problem ? Thank you in advance!

4
  • 1
    this is already encoded data, so use json_decode() to convert it to array Commented Jul 18, 2019 at 10:58
  • 1
    The JSON in the question is not valid JSON, it has several syntax errors. Commented Jul 18, 2019 at 10:59
  • Try using this function to determine the error Commented Jul 18, 2019 at 10:59
  • 1
    Welcome to Stack Overflow! Please take the tour (you get a badge!), have a look around, and read through the help center, in particular How do I ask a good question? I also recommend Jon Skeet's Writing the Perfect Question. We can't help you with code we can't see. Please update the question with a minimal reproducible example (note the "minimal") that demonstrates the problem. Commented Jul 18, 2019 at 10:59

2 Answers 2

0

There is an error in the syntax of your json near to "Product_Name".

The values ​​must be strings and therefore between "".

Tell us if you have resolution problems :)

Have a good day !

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

1 Comment

I did correct the error, it works !
-1

Solution

Use json_decode($jsondata, true) instead.

detailed explanation: json_decode

Propper JSON to use

Also there is a error in your json-string

Here is the propper json to use:

{
    "data": [{
        "Contact_Name": {
            "id": "1884053000034678068"
        },
        "Subject": "1 - XKBKNABJK",
        "Status": "Sans Impact Stock",
        "Entity": "",
        "Etat": "CM - Annul\u00e9",
        "Invoice_Date": "2017-11-21",
        "Discount": 0.000000,
        "Tax": ["TVA"],
        "Total_HT": "55.000000",
        "Total_TVA": 0,
        "Methode_de_paiement": "Payment by check",
        "ID_Lip": "1",
        "Origine": "CM",
        "Type_de_Facture": "Solde",
        "Transporteur": "My carrier",
        "Reference_Colis": "",
        "Billing_Street": "16, Main street",
        "Compl_ment_Facturation": "2nd floor",
        "Billing_City": "Miami",
        "Billing_Country": "\u00c9tats-Unis",
        "Billing_Code": "33133",
        "Shipping_Street": "16, Main street",
        "Compl_ment_Livraison": "2nd floor",
        "Shipping_City": "Miami",
        "Shipping_Country": "\u00c9tats-Unis",
        "Shipping_Code": "33133",
        "Product_Details": [{
            "product": {
                "id": "1884053000030235273"
            },
            "Product_Name": "Blouse - Color: White, Size: M",
            "list_price": 22.5,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
                "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }, {
            "product": {
                "id": "1884053000030235273"
            },
            "Product_Name": "Printed Dress - Color: Orange, Size: S",
            "list_price": 21.67,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
            "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }, {
            "product": {
                "id": "1884053000012868763"
            }, 
            "list_price": 1.67,
            "quantity": 1,
            "Discount": 0,
            "Discount_Amount": 0,
            "line_tax": [{
                "percentage": 20,
                "name": "TVA"
            }]
        }],
        "Adjustment": 0,
        "Montant_TPH": 0,
        "TVA_sur_DEEE_TPH": "0",
        "Taxes_DEEE_TPH": "TPH",
        "Frais_de_port_HT": "2.000000",
        "Frais_de_port_TTC": "2.000000",
        "Nb_produits": 3,
        "Quantite_totale": 3
    }],
    "duplicate_check_fields": ["ID_Lip"],
    "trigger": []
}

For the future

Check your json here for secure results.

I hope this helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.