0

I have an array that looks like this :

[ 
{"value": {
"api_rev":"1.0",
"type":"router",
"hostname":"Router Hasselt",
"lat":50.9307,
"lon":5.33248,
"elev":50,
"aliases":[
          {
           "type":"wired",
           "alias":"11.96.253.9"
           }],
"community":"Antwerpen",
"attributes":{"firmware":""}}}]"

Is it possible to remove [{"value": and obviously the closing of it at the end }] and leave the rest as it is ? I tried unsetting "value" but this actually removes everything which i understand why. But if there is a workaround i will appreciate !

I expect this :

{
    "api_rev":"1.0",
    "type":"router",
    "hostname":"Router Hasselt",
    "lat":50.9307,
    "lon":5.33248,
    "elev":50,
    "aliases":[
              {
               "type":"wired",
               "alias":"11.96.253.9"
               }],
    "community":"Antwerpen",
    "attributes":{"firmware":""}}"

3 Answers 3

2

For example you have this:

$json = json_decode("your stuff");

Then you do:

$json = $json[0]->value;

Then you can encode it back:

$str = json_encode($json);
Sign up to request clarification or add additional context in comments.

1 Comment

json_decode value need to be in string .. how it's possible for array
0

This might help :)

$obj = json_decode($json);
echo json_encode($obj[0]->value);

Comments

0

Try this,

<?php 
$str='[ 
    {"value": {
    "api_rev":"1.0",
    "type":"router",
    "hostname":"Router Hasselt",
    "lat":50.9307,
    "lon":5.33248,
    "elev":50,
    "aliases":[
       {
       "type":"wired",
       "alias":"11.96.253.9"
       }],
    "community":"Antwerpen",
    "attributes":{"firmware":""}}}]';

$json=json_decode($str);

echo json_encode($json[0]->value);

?>

Test it here: DEMO

Comments

Your Answer

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