GitXplorerGitXplorer
m

JSONTypeProvider.jl

public
1 stars
1 forks
3 issues

Commits

List of commits on branch main.
Verified
fc0499b2b515b24fb8f134135ff73c09feab9a82

Update README.md

mmcmcgrath13 committed 4 years ago
Verified
b5fbe70fdb57ce17da6dcfb88ccf12e35877e5d8

Merge pull request #3 from quinnj/jq/nits

mmcmcgrath13 committed 4 years ago
Unverified
30c259fa5be25776515566ddfd78b658351f8b50

Fix Julia 1.0

qquinnj committed 4 years ago
Unverified
b9c07e6a96e98363f262f00ebf63dd71a556ff50

Fix Julia 1.0

qquinnj committed 4 years ago
Unverified
4a512c41e32f5b0e977d54ff0d3aa4ea13abe110

Use a couple of standard reflection conventions

qquinnj committed 4 years ago
Unverified
783a08f79bb4a4dacc929a4003972d4d505234e3

refactor: simply build_type array return type

mmcmcgrath13 committed 4 years ago

README

The README file for this repository.

DEPRECATED - Incorporated into JSON3

JSONTypeProvider

Dev Build Status Coverage

An F# inspired type provider to JSON. Given a JSON3 Object or Array, create a type from it, and write it to file.

import JSON3
import JSONTypeProvider

json = JSON3.read(read("test/menu.json", String)) # either a JSON3.Array or JSON3.Object

# build a type for the JSON
raw_json_type = JSONTypeProvider.build_type(json)
# result:
# NamedTuple{(:menu,),Tuple{NamedTuple{(:header, :items),Tuple{String,Array{Union{Nothing, NamedTuple{(:id, :label),Tuple{String,Union{Nothing, String}}}},1}}}}}

# turn the type into struct expressions, including replacing sub types with references to a struct
json_exprs = JSONTypeProvider.to_exprs(raw_json_type, :MyStruct)
# result:
# 3-element Array{Any,1}:
# :(struct Item
#      id::String
#      label::Union{Nothing, String}
#  end)
# :(struct Menu
#      header::String
#      items::Array{Union{Nothing, Item}, 1}
#  end)
# :(struct MyStruct
#      menu::Menu
#  end)

# write the types to a file, then can be edited/included as needed
JSONTypeProvider.write_exprs(json_exprs, "test.jl")

In the example above, the file test/menu.json:

{
  "menu": {
    "header": "SVG\\tViewer\\u03b1",
    "items": [
      {
        "id": "Open"
      },
      {
        "id": "OpenNew",
        "label": "Open New"
      },
      {
        "id": "ZoomIn",
        "label": "Zoom In"
      },
      null,
      {
        "id": "Help"
      },
      {
        "id": "About",
        "label": "About Adobe SVG Viewer..."
      }
    ]
  }
}

is parsed into the following types:

struct Item
    id::String
    label::Union{Nothing, String}
end

struct Menu
    header::String
    items::Array{Union{Nothing, Item}, 1}
end

struct MyStruct
    menu::Menu
end