Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 questions #16

Open
danielbom opened this issue Mar 7, 2020 · 4 comments
Open

2 questions #16

danielbom opened this issue Mar 7, 2020 · 4 comments

Comments

@danielbom
Copy link

  1. What happening if I use this input? { "a": 1, "a": 2 }

  2. How I can get a value from parsed JSON?
    Ex:
    jsonParsed = runParser $ jsonValue "{ "config": { "mode": "dev" } }"
    jsonGet jsonParsed "config.mode"

@dan323
Copy link
Contributor

dan323 commented Apr 21, 2020

to query a JsonValue, you can implement a jmespath in haskell 👍

@danielbom
Copy link
Author

A simple 'jsonValueByKey objectJson stringKey' it's enough to me.

@dan323
Copy link
Contributor

dan323 commented Apr 23, 2020

The json might not be a jsonObject, so we need something more involved than that. Nevertheless, at the end of the youtube video, if I remeber correctly, there are examples to query the json.

@danielbom
Copy link
Author

danielbom commented Jul 9, 2020

Seeing ramda js, and sanctuary, I believe which a function to retrieve data from Json with this definition, it's a good improvement:

jsonPath :: JsonValue -> [String] -> Maybe JsonValue
jsonPath (JsonObject []) _ = Nothing
jsonPath (JsonObject (x:xs)) keys@(k:ks) =
  if k == fst x
  then jsonPath (snd x) ks
  else jsonPath (JsonObject xs) keys
jsonPath val [] = Just val
jsonPath _ _ = Nothing

Where the array of strings ('[String]') is the a array of keys to the value

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

No branches or pull requests

2 participants