Skip to content

DSL for JSON extraction#538

Merged
xerial merged 2 commits intowvlet:masterfrom
takezoe:json-dsl
Jul 7, 2019
Merged

DSL for JSON extraction#538
xerial merged 2 commits intowvlet:masterfrom
takezoe:json-dsl

Conversation

@takezoe
Copy link
Copy Markdown
Member

@takezoe takezoe commented Jul 6, 2019

Added following methods:

  • JSONObject.get()
  • JSONArray.apply()

Also added JSON extraction DSL for ease:

val json = """{"user": [{ "id": 1 }, { "id": 2 }]}"""
val id = (JSON.parse(json) / "user" / "id")(0).value.asInstanceOf[Long] // => 1

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 6, 2019

Codecov Report

Merging #538 into master will decrease coverage by 0.04%.
The diff coverage is 64.7%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #538      +/-   ##
==========================================
- Coverage   83.91%   83.87%   -0.05%     
==========================================
  Files         217      217              
  Lines        8077     8094      +17     
  Branches      593      616      +23     
==========================================
+ Hits         6778     6789      +11     
- Misses       1299     1305       +6
Impacted Files Coverage Δ
...json/src/main/scala/wvlet/airframe/json/JSON.scala 69.56% <100%> (+2.12%) ⬆️
...n/src/main/scala/wvlet/airframe/json/package.scala 60% <57.14%> (-40%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a031ea7...3755650. Read the comment docs.

@xerial
Copy link
Copy Markdown
Member

xerial commented Jul 7, 2019

Thanks!

Honestly speaking I don’t like \ syntax. Can’t we use / instead? It can be confusing with the string division operator, but sbt is already using / for file paths without causing such a confusion. So I guess it should be possible to use / for JSONValue.

@takezoe
Copy link
Copy Markdown
Member Author

takezoe commented Jul 7, 2019

I got you. Updated to use / instead.

@xerial xerial merged commit 21a6204 into wvlet:master Jul 7, 2019
@xerial
Copy link
Copy Markdown
Member

xerial commented Jul 7, 2019

Looks good. Merged

@takezoe takezoe mentioned this pull request Jul 7, 2019
@xerial xerial mentioned this pull request Jul 7, 2019
66 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants