Code Monkey home page Code Monkey logo

json.jl's Introduction

JSON.jl

Parsing and printing JSON in pure Julia.

Build Status Build status codecov.io

JSON JSON JSON JSON

Installation: julia> Pkg.add("JSON")

Basic Usage

import JSON

# JSON.parse - string or stream to Julia data structures
s = "{\"a_number\" : 5.0, \"an_array\" : [\"string\", 9]}"
j = JSON.parse(s)
#  Dict{AbstractString,Any} with 2 entries:
#    "an_array" => {"string",9}
#    "a_number" => 5.0

# JSON.json - Julia data structures to a string
JSON.json([2,3])
#  "[2,3]"
JSON.json(j)
#  "{\"an_array\":[\"string\",9],\"a_number\":5.0}"

Documentation

JSON.print(io::IO, s::AbstractString)
JSON.print(io::IO, s::Union{Integer, AbstractFloat})
JSON.print(io::IO, n::Nothing)
JSON.print(io::IO, b::Bool)
JSON.print(io::IO, a::Associative)
JSON.print(io::IO, v::AbstractVector)
JSON.print{T, N}(io::IO, v::Array{T, N})

Writes a compact (no extra whitespace or indentation) JSON representation to the supplied IO.

JSON.print(a::Associative, indent)
JSON.print(io::IO, a::Associative, indent)

Writes a JSON representation with newlines, and indentation if specified. Non-zero indent will be applied recursively to nested elements.

json(a::Any)

Returns a compact JSON representation as an AbstractString.

JSON.parse(s::AbstractString; dicttype=Dict, inttype=Int64)
JSON.parse(io::IO; dicttype=Dict, inttype=Int64)
JSON.parsefile(filename::AbstractString; dicttype=Dict, inttype=Int64, use_mmap=true)

Parses a JSON AbstractString or IO stream into a nested Array or Dict.

The dicttype indicates the dictionary type (<: Associative) that JSON objects are parsed to. It defaults to Dict (the built-in Julia dictionary), but a different type can be passed to, for example, provide a desired ordering. For example, if you import DataStructures (assuming the DataStructures package is installed), you can pass dicttype=DataStructures.OrderedDict to maintain the insertion order of the items in the object.

The inttype argument controls how integers are parsed. If a number in a JSON file is recognized to be an integer, it is parsed as one; otherwise it is parsed as a Float64. The inttype defaults to Int64, but, for example, if you know that your integer numbers are all small and want to save space, you can pass inttype=Int32. Alternatively, if your JSON input has integers which are too large for Int64, you can pass inttype=Int128 or inttype=BigInt. inttype can be any subtype of Real.

JSONText(s::AbstractString)

A wrapper around a Julia string representing JSON-formatted text, which is inserted as-is in the JSON output of JSON.print and JSON.json.

JSON.lower(p::Point2D) = [p.x, p.y]

Define a custom serialization rule for a particular data type. Must return a value that can be directly serialized; see help for more details.

json.jl's People

Contributors

totalverb avatar aviks avatar westleyargentum avatar iainnz avatar tkelman avatar stevengj avatar yuyichao avatar kmsquire avatar dirk avatar jiahao avatar stefankarpinski avatar jakebolewski avatar keno avatar staticfloat avatar daviddelaat avatar jeffbezanson avatar mweastwood avatar timholy avatar tanmaykm avatar scottpjones avatar ivarne avatar ssfrr avatar randyzwitch avatar nolta avatar astrieanna avatar quinnj avatar iamed2 avatar dcjones avatar christopherdavidwhite avatar chief-pita avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.