Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Offer API to expose source maps of parsed JSON documents #12

Open
kylef opened this issue Mar 16, 2016 · 4 comments
Open

Offer API to expose source maps of parsed JSON documents #12

kylef opened this issue Mar 16, 2016 · 4 comments

Comments

@kylef
Copy link

kylef commented Mar 16, 2016

In some cases, I could see a use for having source maps for parsed JSON documents. For example, the character positions of parse JSON elements.

What do you think about this?

An example use-case could be for using JSON data used in tests and providing the exact location of a failure in a test.

@czechboy0
Copy link
Collaborator

Sounds like a feature I'd welcome! I could try to hack it together.

  • are you looking for just an index in the byte stream or would you prefer line/column information?
  • how would you structure the API?

@czechboy0
Copy link
Collaborator

@kylef Okay, here's a working implementation on a branch, I'll wait for your feedback before I merge it.

Call this:

let json: ParsedJsonToken = try Jay().annotatedTypesafeJsonFromData(data)

and it returns

public struct ParsedJsonToken {
    public let value: ParsedJsonValue
    public let range: JsonRange
}

@kylef
Copy link
Author

kylef commented Mar 18, 2016

This looks awesome, I'd say go with index since line number can always be found out afterwards and it's more accurate (if the JSON document wasn't pretty printed and in a single line).

You can also change all of the errors thrown from Jay to contain source annotations too so people can easily find where a problem lies in their JSON document.

I will try find some time tomorrow evening to try and use this. I'd also like to update my JSONSchema library to use Jay and try these source annotations. Would be helpful to indicate where validation warnings are raised from within the JSON document.

@czechboy0
Copy link
Collaborator

Great, give it a try and let me know what you want changed. Happy to see
Jay stress tested in different use cases.
On Fri, Mar 18, 2016 at 2:22 AM Kyle Fuller [email protected]
wrote:

This looks awesome, I'd say go with index since line number can always be
found out afterwards and it's more accurate (if the JSON document wasn't
pretty printed and in a single line).

You can also change all of the errors thrown from Jay to contain source
annotations too so people can easily find where a problem lies in their
JSON document.

I will try find some time tomorrow evening to try and use this. I'd also
like to update my JSONSchema https://github.com/kylef/JSONSchema.swift
library to use Jay and try these source annotations. Would be helpful to
indicate where validation warnings are raised from within the schema.


You are receiving this because you commented.

Reply to this email directly or view it on GitHub
#12 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants