Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 521

manipulate php config file

$
0
0

What's the correct way to automate manipulation of a php config file of this format?

sample.php:<?phpreturn ['someobject' => ['somefield' => 'somevalue'    ]];

I was thinking of converting it to JSON (json_encode), manipulate the JSON and writing it back afterwards (json_decode). But the last step gives me a different data format.

# !/bin/bash# load data to jsonJSON=$(php -r "echo json_encode(include 'sample.php');")# manipulate json with jqNEW_JSON=$(echo $JSON | jq -cr '.someobject.somefield = "othervalue"')# write backphp -r "var_dump(json_decode('$NEW_JSON', true));" > sample2.php

The content I'm getting from json_decode is:

array(1) {  ["someobject"]=>  array(1) {    ["somefield"]=>    string(10) "othervalue"  }}# or without true in json_decodeobject(stdClass)#2 (1) {  ["someobject"]=>  object(stdClass)#1 (1) {    ["somefield"]=>    string(10) "othervalue"  }}

What's the correct way of manipulating this type of config files?


Viewing all articles
Browse latest Browse all 521

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>