-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add 'to-json' expression #7796
Add 'to-json' expression #7796
Conversation
Thanks for this idea and implementation @stepankuzmin ! The native implementation of expressions does not have the same JSON support as provided by |
That is possible in Objective-C, via the NSJSONSerialization class. |
Given that expression evaluation is happening in C++ code anyway, and we already have a JSON parser in there, we'd just parse the JSON code there. Taking a step back though, I'm not convinced that adding the ability to parse JSON fosters good vector tile design, since it usually means that you haven't spent much time thinking about your data model. You're right in pointing out that vector tiles currently don't support nested properties and arrays, which make some data models complicated to implement in vector tiles. However, instead of JSON support, we should work towards mapbox/vector-tile-spec#75. |
This is a long awaited one, it is often needed to include json structured data in feature properties. I.e. in my case I'm packing an array of numbers into a property, so parsing this encoded string to an object is a first step to working with arrays - values and indexes. In conjunction with this feature it becomes extremely useful. Surely there are more use cases for this. Please merge for greater good. |
I agree with that, but sometimes it's better to encode attribute into an array instead of using a list of flat properties, which may lead to bloated tiles. |
Any news here? |
Hi everyone! I've added tests for |
Would love to see this get merged |
Bump to see this merged. Really important for a project I'm working on. |
Still hoping to see this merged. |
Hi @stepankuzmin thanks again for your suggestion of this feature & your very diligent & thorough work on this PR! And thanks everyone else for supporting this - We so appreciate your contributions to this project & discussions around its feature roadmap. We have discussed this suggestion at length as a team, so let me sum up our thoughts & conclusions here. We hear all of your frustrations with the lack of structured data support in tile properties, and we hear your vocal support for this expression. But as @kkaefer explained above, adding JSON parsing would only be a workaround for the real problem. The best long-term solution will be actual support for structured data in the source itself, and work is already underway on other teams at Mapbox to solve that & related problems in a holistic way. That said, even if a All of this brings us to the conclusion that a |
Hi there!
Sometimes there is a need to encode some structured data in a feature property. Current vector tiles spec does not support compound properties, such as arrays and objects. We can encode such properties as a stringified JSON.
This PR adds
to-json
expression, that allows parsing stringified JSON.Consider example:
If you have a features with stringified object or array properties, you can use the following expressions to obtain JSON values:
What do you think of this?