JuliaData / JuliaData/StructTypes.jl

Inverse of `fieldprefix` function

Open
#10 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
86
Forks
21
PR merge metrics
No merged PRs in 30d

Description

There is fieldprefix function, which transform flat structure into nested objects. Is it possible in some way to have an opposite operation?

As an example, consider following article structure written in json:
Input:

json_str = """
{
  "author": {
      "name": "XXX"
      "link": "https://example.com"
  },
  "title": "YYY",
  "body": "ZZZ"
}
"""

What I want is to put it in flat structure (because in my particular case I do not need author as a separate object)

struct Article
   author_name::String
   author_link::String
   title::String
   body::String
end

And to be able to read articles with the construct like

JSON3.read(json_str, Article)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing fieldprefix function and how JSON3.read(json_str, Article) handles nested fields. Define the inverse mapping needed for author.name and author.link to populate author_name and author_link, with successful deserialization into the shown Article structure as the completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.