lukascivil / treewalker Goto Github PK
View Code? Open in Web Editor NEWPHP JSON diff
Home Page: http://treewalker.lukascivil.com.br/
License: MIT License
PHP JSON diff
Home Page: http://treewalker.lukascivil.com.br/
License: MIT License
An empty array in a structure equals a structure without this array.
Lukas,
When is the next tag coming? This would help lower the stability level in Packagist
HI, thanks for this fantastic code...
i have a litlle problem.
Im receiving this answer with this
$treewalker->getdiff($json1, $json2);
array:3 [▼
"new" => array:63 [▼
"shipping/id" => "123456"
how can i do to receive the array like array ?
array:3 [▼
"new" => array:63 [▼
"shipping" => array [
"id" => "21665181130"
thanks !!
Hello,
I would like to use this cool php library to store only overrided value of JSON config files inside a database.
I just need to have the modified value with original structure, I don't need to keep the pretty useless oldvalue.
How can I easily do that (without recursively delete all old value and move the new one) ?
Thanks for your work.
en la linea 188 dice
if ($key != "_id") {
deberia decir
if ($key !== "_id") {
porque si viene un array con indices numericos
por ej
nombres = ['juan', 'ramon', 'gonzalo']
al hacer el diff devuelve
nombres/ = juan
nombres/1/ = ramon
nombres/2/ = gonzalo
Mind to add a composer.json and maybe publish to https://packagist.org/ ?
Hi,
When I compare 2 array (no key, just array for the root element), structPathArray miss the first 'key'.
I had to add to change your test :
$path = $currentpath !== '' ? $currentpath . "/" . $key : sprintf($key);
Do you prefer a pull request ?
Hello,
I have the following problem. I want to walk through a tree and give all nodes with the key equal "key" a new increasing number (starting at 100). But after walker() function the tree is corrupted:
$tree = '{"key":"root_1","title":"root","children":[{"title": "Node 1", "key": "1"},{"key":"2","title":"Folder 2","children":[{"key":"3","title":"Node 2.1"},{"key":"4","title":"Node 2.2"}]}]}';
$tree = json_decode($tree, true);
print_r($tree);
$counter = 100;
$treewalker = new TreeWalker([]);
$treewalker->walker($tree, function(&$tree, $key, &$value) use (&$counter) {
if ($key == "key") {
$value = $counter++;
}
});
print_r($tree);
The code above has the following output:
Array
(
[key] => root_1
[title] => root
[children] => Array
(
[0] => Array
(
[title] => Node 1
[key] => 1
)
[1] => Array
(
[key] => 2
[title] => Folder 2
[children] => Array
(
[0] => Array
(
[key] => 3
[title] => Node 2.1
)
[1] => Array
(
[key] => 4
[title] => Node 2.2
)
)
)
)
)
Array
(
[key] => 100
[title] => root
[children] => Array
(
[0] => 101
[1] => Array
(
[key] => 102
[title] => Folder 2
[children] => Array
(
[0] => 103
[1] => Array
(
[key] => 104
[title] => Node 2.2
)
)
)
)
)
Could you please look into this issue?
I use PHP 5.6.24 and the latest Treewalker.php (17.02.2018)
Best regards,
Mario
Hey thanks for this nice lib.
Is there any way of just checking the keys / labels and ignoring the values?
I'm seeing an issue with Treewalker flagging integer values as edited, even though they are unchanged.
For example I get the following data snippet from an aws config file:
{
"LoadBalancerAttributes": {
"crossZoneLoadBalancing": {
"enabled": false
},
"accessLog": {
"enabled": false
},
"connectionDraining": {
"enabled": false,
"timeout": 300
},
"connectionSettings": {
"idleTimeout": 60
},
"additionalAttributes": []
},
"LoadBalancerPolicies": [],
"Tags": [
{
"key": "Name",
"value": "zabbix-server-dev"
}
]
}
One hour later, I get query aws again and get an identical result but Treewalker reports the following:
{
"new":[
],
"removed":[
],
"edited":{
"LoadBalancerAttributes/connectionDraining/timeout":{
"oldvalue":300,
"newvalue":300
},
"LoadBalancerAttributes/connectionSettings/idleTimeout":{
"oldvalue":60,
"newvalue":60
}
}
}
The values are unchanged, so why does Treewalker report them as edited?
"true" and true are not found as differences
Hi, i face an issue. I had two array and need a nested array instead of parent/child, it will be more usefully in my case parent => [child => [] ].
My full example, first the arrays to compare, the original result and the desire result.
$array1 = array(
0 => array(
"key" => "val",
"etc" => "val",
),
);
$array2 = array(
0 => array(
"key" => "val1",
"etc" => "val2",
),
);
$array1 = array(
"edited" =>
array(
"0/key" => array( "oldvalue" => "val", "newvalue" => "val1" ),
"0/etc" => array( "oldvalue" => "val", "newvalue" => "val2" )
)
);
$array1 = array(
"edited" =>
array(
"0" => array(
"key" => array( "oldvalue" => "val", "newvalue" => "val1" ),
"etc" => array( "oldvalue" => "val", "newvalue" => "val1" )
),
)
);
Thanks in advance for your help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.