Чтобы прочитать файл JSON и распечатать его содержимое в формате JSON, вы можете использовать различные языки программирования. Вот несколько примеров на популярных языках:
Python:
import json
# Open the JSON file
with open('file.json') as f:
# Load the content
data = json.load(f)
# Print the content in JSON format
print(json.dumps(data, indent=4))
JavaScript:
const fs = require('fs');
// Read the JSON file
fs.readFile('file.json', 'utf8', (err, data) => {
if (err) throw err;
// Parse the JSON content
const jsonData = JSON.parse(data);
// Print the content in JSON format
console.log(JSON.stringify(jsonData, null, 4));
});
Java:
import org.json.JSONObject;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;
public class JsonReader {
public static void main(String[] args) {
try {
// Read the JSON file
String content = new String(Files.readAllBytes(Paths.get("file.json")));
// Parse the JSON content
JSONObject json = new JSONObject(content);
// Print the content in JSON format
System.out.println(json.toString(4));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Эти примеры демонстрируют, как прочитать файл JSON и распечатать его содержимое в удобочитаемом формате JSON с использованием Python, JavaScript и Java. Вы можете выбрать язык программирования, который соответствует вашим потребностям.