preveen-stack / test

0 stars 0 forks source link

JSON with julia #19

Open preveen-stack opened 1 year ago

preveen-stack commented 1 year ago

Sure! Here's an example of a Julia script that uses the JSON package to pretty print JSON data:

using JSON

function pretty_print_json(json_string::AbstractString)
    json_data = JSON.parse(json_string)
    println(JSON.json(json_data, 4))
end

# Example usage:
json_string = """
{
  "name": "John",
  "age": 30,
  "city": "New York"
}
"""

pretty_print_json(json_string)

In this example, the JSON package is imported using the using statement. The pretty_print_json function takes a JSON string as input, parses it using JSON.parse, and then prints the parsed JSON data using JSON.json with an indentation of 4 spaces, which makes the JSON data appear "pretty" or formatted with proper indentation. You can adjust the indentation level by changing the second argument of JSON.json function accordingly.