how to remove back slashes from json output in php

php trim slashes
php escape slashes
slashes in json response php
stripslashes in javascript
how to remove backslash from json data in php
json_unescaped_slashes not working
how to remove backslash from url in php
remove from json encode in php

The code I have used:

$val = json_encode(array("test"=>test1,"test2" =>test,"description" => description));
return $val;

The result im getting

{\"test\":\"test1\",\"test2\":\"test\",\"description\":\"description\"}

I need this to fix api

Try with stripslashes()

echo stripslashes('{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}');

stripslashes()

how remove the backslash ("\") in the json response using php , PHP stripslashes() Function. ❮ PHP String Reference. Example. Remove the backslash: <?php echo stripslashes("  I mean the php script. Could you show us that code – Harigovind R May 15 '15 at 6:52 this is just a sample output.I need to remove the back slashes – Aparna May 15 '15 at 6:55

In php "stripslashes" function is present using that you can remove backslash.

Link for more details.

Example:

echo $strnew = stripslashes('{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}');

PHP stripslashes() Function, Un-quotes a quoted string. Note: If magic_quotes_sybase is on, no backslashes are stripped off but two apostrophes are replaced by one instead. An example  If magic_quotes_sybase is on, no backslashes are stripped off but two apostrophes are replaced by one instead. An example use of stripslashes() is when the PHP directive magic_quotes_gpc is on (it was on by default before PHP 5.4), and you aren't inserting this data into a place (such as a database) that requires escaping. For example, if you're simply outputting data straight from an HTML form.

Use stripslashes() And read stripslashes

<?php
$srt="'{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}'
";
echo stripslashes($srt);

OUTPUT

'{"test":{"test1":{"test1":[{"test2":"1","test3": "foo","test4":"bar","test5":"test7"}]}}}'

stripslashes - Manual, classes/class-ep-debug-bar-elasticpress.php <pre class="query-body"><?php echo esc_html( stripslashes( json_encode( json_decode( $query['args']['body'],  JSON_PARTIAL_OUTPUT_ON_ERROR options was added. 5.5.0: When value triggers a JSON encoding error, FALSE is returned instead of partial output, unless options contains JSON_PARTIAL_OUTPUT_ON_ERROR. See json_last_error() for the full list of reasons that can cause JSON encoding to fail.

Tried this.

$val = json_encode(array(
  "test"=>'test1',
  "test2" =>'test',
  "description" => 'description'
));

$data = json_decode($val, true, JSON_UNESCAPED_SLASHES);
return $data;

This is the result I received.

Remove stripslashes so that valid JSON displays in the debug output., I've created a json object which I'm adding value like json.put(key, value). http://​stackoverflow.com/questions/21036626/remove-backslashes-from-json-data-  World's simplest online string and text slash remover tool. Just paste your backslash-escaped text in the form below, press Strip Slashes button, and all backslashes get unescaped. Press button, unescape slashes. No ads, nonsense or garbage. Apply multiple times to remove all slashes.

you can use JSON_UNESCAPED_SLASHES

json_encode($yourjson, JSON_UNESCAPED_SLASHES);

Solved: Remove backslash from Json Object, I am using this code that I got from git, and when I get the BlockChain API response while ($response->address); How to remove the quotes? The answer is simple: there is no backslash in the string! What you're seeing is the Visual Studio debugger's representation of the string. Since you're using C#, it displays the string with the escape characters you would need to include to type that value as a string literal in your C# code.

Removing double quotes from a string from JSON response in PHP , Once you've got your response without slashes, you can use the following one-​line to force PHP to convert the string into a JSON object: When I output the JSON string without Oj I don't get any backslashes. When I add Oj.dump() I do get the backslashes. I understand that the backslashes are there because the string is itself eclosed within another string, but it seems to me that what is eclosing the original string within a second string is Oj no?

How to return a JSON object with a custom REST API in Magento 2 , PHP String Exercises, Practice and Solution: Write a PHP script to remove trailing slash from a string. API Twitter REST API Data Interchnage XML JSON Ajax Exercises HTML PHP String Exercises: Remove trailing slash from a string The output is more detailed as compared to print_r because it also  I need to save the original JSON I'm getting in the REST POST call-in to later send it in a callout. To do that I have a text field on the object I create which holds the JSON string. The problem is that a backslash is added before each double quote, and the system that gets this JSON when I callout can't process it.

PHP String Exercise: Remove trailing slash from a string, I am tryng to populate a SELECT from PHP and Jquery but the output I then JSON.parse in a browser or json_decode in php that string, I get  A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

Comments
  • From where do u get this output? I mean the php script. Could you show us that code
  • this is just a sample output.I need to remove the back slashes
  • But the point is, where are you getting the top one from? A JSON Decode? An API? Because that could effect the answer
  • @Aparna If it is the issue of the code or it happens when you assign the json value then its better to solve it at the begining rather than at the end using stripslashes()...
  • I used a combination of your answer and the following answer - json_decode(stripslashes($val), true, JSON_UNESCAPED_SLASHES); - thank you
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
  • Thanks. I have added more detail for the answer.
  • Your answer worked for me, Thanks @KajornjitSongsaen