Question: Let's say I have such JSON:

```
{
 id: 1,
 somevalue: "text"
}

```

and I want to create this JSON by PHP function [json\_encode](http://php.net/manual/en/function.json-encode.php). I can pretty easy get this JSON in form:

```
{
 "id": "1",
 "somevalue": "text"
}

```

or, using `JSON_NUMERIC_CHECK`, in form where "id" will be numeric, but "somevalue" can be either numeric or text, depend on its content.

How can I make JSON where "somevalue" always be in text format (with quotes). I'll parse it by other language, where it is important.

Answer: 
To make `somevalue` always in "text" format:

```
$somevalue1 = 1;
$somevalue2 = "text";

$json1 = array("id" => 1, "somevalue" => (string) $somevalue1);
$json2 = array("id" => 1, "somevalue" => (string) $somevalue2);

echo json_encode($json1); // outputs {"id":1,"somevalue":"1"}
echo json_encode($json2); // outputs {"id":1,"somevalue":"text"}

```
Make sure values you want to be non string (like int or boolean) are entered as such into your source array:

```
<?php
$a = array('id' => 1, 'really' => true, 'somevalue' => 'text');
var_dump( json_decode( json_encode( $a ) ) );

```

gives expected:

```
object(stdClass)#1 (2) {
  ["id"]=>
  int(1)
  ["really"]=>
  bool(true)
  ["somevalue"]=>
  string(4) "text"
}

```

**EDIT**

If you want it always to be strings, then put strings in your array in first place:

```
<?php
$a = array('id' => '1', 'really' => 'true', 'somevalue' => 'text');
var_dump( json_decode( json_encode( $a ) ) );

```

would give

```
object(stdClass)#1 (3) {
  ["id"]=>
  string(1) "1"
  ["really"]=>
  string(4) "true"
  ["somevalue"]=>
  string(4) "text"
}

```

but that kills the whole purpose of having different variable types.

Of you can convert your array prior json encoding:

```
<?php
$a = array('id' => 1, 'really' => true, 'somevalue' => 'text');

$tmp = array();
foreach( $a as $key=>$val ) {
   $tmp[$key] = (string)$val;
}

var_dump( json_decode( json_encode( $tmp ) ) );

```

would give in the end:

```
object(stdClass)#1 (3) {
  ["id"]=>
  string(1) "1"
  ["really"]=>
  string(1) "1"
  ["somevalue"]=>
  string(4) "text"
}

```