0

Am getting json results in php as follows:

{ "dataset": [{"seriesname": "Soap","data": [ { "value": "90000" }]},{"seriesname": "Dummy","data": [ { "value": "70000" }]} ]}

Pls help me in making pretty and removing the first and last curly braces

I want the result in this way:

 "dataset": [{"seriesname": "Soap","data": [ { "value": "90000" }]},{"seriesname": "Dummy","data": [ { "value": "70000" }]} ]

2 Answers2

1

What you want isn't json. But if you really want it, you could just use trim to remove the leading and trailing curly brakets.

$noJson = trim($json, "{}");

if it is important, that you just remove one curly, you should maybe use an regex

$noJson = preg_replace('/\{(.*)\}/', '$1', $json);
Philipp
  • 15,377
  • 4
  • 35
  • 52
0

To remove first and last curly braces:

$string = '{ "dataset": [{"seriesname": "Soap","data": [ { "value": "90000" }]},{"seriesname": "Dummy","data": [ { "value": "70000" }]} ]}';

echo $result = substr($string, 1, -1);
mith
  • 1,680
  • 1
  • 10
  • 12