0

I have this JSON array starting with the nesting string "ELEVEURS" and I want to have it removed and should get the output as below. Could someone solve this please!

INPUT

 $json='{ "ELEVEURS" : 
       [{
        "CHEPTEL":"12001116",
        "NOM":"La Ferme de Jean-Marc et Aurélien ",
        "CODE_POSTAL":"12630                         ",
        "VILLE":"AGEN D AVEYRON",
        "LATITUDE":"44.343518",
        "LONGITUDE":"2.716004",
        "DESCRIPTIF_FERME":"",
        "DEMARCHE" : [
        {
        "DEMA_CODE":"08-93",
        "ANNEE_ADHESION":"2016",
        "RACE_MERES":"Limousine",
        "DESCRIPTIF_ATELIER":""
        }
        ]
        },
        {
        "CHEPTEL":"12004022",
        "NOM":"La Ferme du Broussier ",
        "CODE_POSTAL":"12300                         ",
        "VILLE":"ALMONT LES JUNIES",
        "LATITUDE":"44.592071",
        "LONGITUDE":"2.328516",
        "DESCRIPTIF_FERME":"",
        "DEMARCHE" : [
        {
        "DEMA_CODE":"08-93",
        "ANNEE_ADHESION":"2000",
        "RACE_MERES":"Limousine",
        "DESCRIPTIF_ATELIER":""
        }
        ]
        }'

OUTPUT

$json='  [{
        "CHEPTEL":"12001116",
        "NOM":"La Ferme de Jean-Marc et Aurélien ",
        "CODE_POSTAL":"12630                         ",
        "VILLE":"AGEN D AVEYRON",
        "LATITUDE":"44.343518",
        "LONGITUDE":"2.716004",
        "DESCRIPTIF_FERME":"",
        "DEMARCHE" : [
        {
        "DEMA_CODE":"08-93",
        "ANNEE_ADHESION":"2016",
        "RACE_MERES":"Limousine",
        "DESCRIPTIF_ATELIER":""
        }
        ]
        },
        {
        "CHEPTEL":"12004022",
        "NOM":"La Ferme du Broussier ",
        "CODE_POSTAL":"12300                         ",
        "VILLE":"ALMONT LES JUNIES",
        "LATITUDE":"44.592071",
        "LONGITUDE":"2.328516",
        "DESCRIPTIF_FERME":"",
        "DEMARCHE" : [
        {
        "DEMA_CODE":"08-93",
        "ANNEE_ADHESION":"2000",
        "RACE_MERES":"Limousine",
        "DESCRIPTIF_ATELIER":""
        }
        ]'

I have this INPUT of JSON array starting with the nesting string "ELEVEURS" and I want to have it removed and should get the output as above. Could someone solve this please!

5
  • I think you're building something; would you like to tell us why you're using this JSON? Commented Feb 2, 2022 at 15:37
  • 1
    Please post the code you already have along with any errors you might get. This is not a coding service (as already stated in your other question) Commented Feb 2, 2022 at 15:51
  • @ArRakin Thanks Again. Sure, Its just that I am a beginner to PHP and I am very fond of PHP particularly. I took a sample data of arrays from a friend. Trying to create a system on my own to automate data from one FTP to Another without having to code it every time something is updated. And I should tell you, I feel like addicted to it. Commented Feb 2, 2022 at 16:00
  • @brombeer Hello, I am very new this platform and I have my own code with errors but thought It might not be useful, So I didn't post it. Its just that I didn't know how things work here. But thank you for letting me know. I will try to blend in with everyone. Commented Feb 2, 2022 at 16:02
  • @RanjitT As brombeer said, StackOverflow is not a coding service, so if you want then you can join my organization's forum at forums.onesoftnet.ml and post your problems there, I'll be happy to assist you. Commented Feb 2, 2022 at 16:34

1 Answer 1

1

I think you have a syntax error in your first JSON. I've corrected it in this answer.

$json = '
{
     "ELEVEURS": [
          {
            "CHEPTEL":"12001116",
            "NOM":"La Ferme de Jean-Marc et Aurélien ",
            "CODE_POSTAL":"12630                         ",
            "VILLE":"AGEN D AVEYRON",
            "LATITUDE":"44.343518",
            "LONGITUDE":"2.716004",
            "DESCRIPTIF_FERME":"",
            "DEMARCHE" : [
                {
                "DEMA_CODE":"08-93",
                "ANNEE_ADHESION":"2016",
                "RACE_MERES":"Limousine",
                "DESCRIPTIF_ATELIER":""
                }
            ]
          },
          {
                "CHEPTEL":"12004022",
                "NOM":"La Ferme du Broussier ",
                "CODE_POSTAL":"12300                         ",
                "VILLE":"ALMONT LES JUNIES",
                "LATITUDE":"44.592071",
                "LONGITUDE":"2.328516",
                "DESCRIPTIF_FERME":"",
                "DEMARCHE" : [
                    {
                        "DEMA_CODE":"08-93",
                        "ANNEE_ADHESION":"2000",
                        "RACE_MERES":"Limousine",
                        "DESCRIPTIF_ATELIER":""
                    }
                ]
            }
       ]
}';


echo(json_encode(json_decode($json)->ELEVEURS, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); // done!
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.