Question:
I have a json file where I am listing the information that I am interested with with PHP.
I'm using Lottie.js to run this .json as a gif/video, my idea is to change the messages from English to Portuguese, I'm able to list them from json, but I don't know how to change it, follow my code:
<?php
$url = 'js/data3.json';
$jsonStr = file_get_contents($url);
$jsonArr = json_decode($jsonStr, true);
$titulo = array();
foreach ($jsonArr['layers'] as $row) {
$titulo[] = $row['nm'];
}
?>
the result I'm getting is:
Keep an eye out for an email
Message sent
Send Message
(is bringing the texts)
How do I change the Message sent
value per Mensagem enviada
for example?
Json Link: https://jsonditoronline.org/?id=e231e4df96f349f281002c689d84ab0f
Answer:
My first interaction with JSON with PHP, I had already done something a little more complex with XML, but the idea is the same, the functions that change:
I saved the json in a .JSON
file in the same folder as the PHP file.
<?php
//abrindo o json externo
$json = json_decode(file_get_contents('teste.json'));
//Editando a linha que vc quer
$json->layers[1]->nm = "Mensagem Enviada";
//Salvando as edições
$json_editado = file_put_contents('teste.json',json_encode($json));
//Carregando json após ser salvo já editado
$json = json_decode(file_get_contents('teste.json'));
//Imprimindo json editado
var_dump($json);
?>
What can mess up a little is that part of json has an Array, and it can mess up a little when it comes to the attribute or object.