title: Where to place input JSON file inside Haskell's stack project folder?
body: <p>I'm new to Haskell as well as Stack. This would be one of my first few programs in Haskell. Hence, unable to make it work correctly so far.</p>
  <ol>
  <li><p>With the help of a small Haskell program, a JSON file (a short summary of statistics data from a website - in nested JSON format) was obtained. I got that inside 'App' folder of that stack project.</p>
  </li>
  <li><p>In the next program/stack-project, we try to parse the data.json (obtained in the previous program) and get only certain portion of that statistics  displayed/printed in ghci - in a list format (with the help of forM_ [decoded-JSON's-certain-portion-of-data-in-list-format] (print . name)). Since the 'decode-JSON' function (from Data.Aseon) would produce results in Maybe format, we also do pattern-matching to display 'Error - loading data' in case the result is nothing; And, do forM_ when there is Just data.</p>
  </li>
  <li><p>My issue is that - Code compiles; But, says 'Error - loading failed' even when I had placed the data.json inside this particular stack project's folder.</p>
  </li>
  </ol>
  <ul>
  <li>have added 'import System.IO' in Main module.</li>
  <li>have added &quot;Data-files: (/n)-data.json&quot; inside package.yaml - at the top, right below the 'extra-source-files' details.</li>
  </ul>
  <p>I didn't make any manual update inside cabal file. Stack wouldn't let me do any manual change in cabal file and asks me to delete either cabal or package.yaml. There are no such errors/warnings thrown by stack, when package.yaml is updated with the details of 'Dependencies and Extensions' details,etc. Hence, I updated this data.json info in package.yaml.</p>
  <p>(Though I am not sure which is the right location inside stack-proj-folder, where the input data ought to be placed.</p>
  <ul>
  <li><p>I tried placing it as one of the elements in the root folder of the project, along with package.yaml, cabal file and stack.yaml etc;</p>
  </li>
  <li><p>I also placed a copy of data.json file - inside 'app' folder - along with Main.hs file (as that's where the output what placed by stack in the previous program. Hence, assumed stack might look consider this folder for input/output files, though I'm not sure and it doesn't seem to work as expected);</p>
  </li>
  <li><p>I also made one additional folder named 'data' (just like src, app and test) , and have placed a copy of data.json file inside that. Though I haven't given any description inside package.yaml for this new 'data' folder, as I wasn't sure of the right way to do it)</p>
  </li>
  </ul>
  <p>But, irrespective of all these places I have tried placing the input data.json file - for stack to access and read, it doesn't seem to work so. The compiled code always returns 'Error loading data' - indicating the decodeJSON function returned nothing/no-data - even though the file/data-format is valid. (It was not manually prepared file - where the error could occur due to manual formatting; It was just a system produced JSON file data from a website. And, it has valid data for decoding)</p>
  <p>I am attaching</p>
  <ul>
  <li>package.yaml update</li>
  <li>data.json file's data</li>
  <li>Main module code
  here for reference.</li>
  </ul>
  <p>At the top of packagae.yaml :</p>
  <pre><code>   extra-source-files:
      - README.md
      - ChangeLog.md
  
     data-files:
      - data.json
  </code></pre>
  <p>The data in the file named &quot;data.json&quot; :</p>
  <pre><code>    {&quot;metadata&quot;:{&quot;resultset&quot;:{&quot;offset&quot;:1,&quot;count&quot;:11,&quot;limit&quot;:25}},&quot;results&quot;:[{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00861&quot;,&quot;mindate&quot;:&quot;1763-01-01&quot;,&quot;maxdate&quot;:&quot;2021-07-02&quot;,&quot;name&quot;:&quot;Daily Summaries&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;GHCND&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00946&quot;,&quot;mindate&quot;:&quot;1763-01-01&quot;,&quot;maxdate&quot;:&quot;2021-06-01&quot;,&quot;name&quot;:&quot;Global Summary of the Month&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;GSOM&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00947&quot;,&quot;mindate&quot;:&quot;1763-01-01&quot;,&quot;maxdate&quot;:&quot;2021-01-01&quot;,&quot;name&quot;:&quot;Global Summary of the Year&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;GSOY&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00345&quot;,&quot;mindate&quot;:&quot;1991-06-05&quot;,&quot;maxdate&quot;:&quot;2021-07-02&quot;,&quot;name&quot;:&quot;Weather Radar (Level II)&quot;,&quot;datacoverage&quot;:0.95,&quot;id&quot;:&quot;NEXRAD2&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00708&quot;,&quot;mindate&quot;:&quot;1994-05-20&quot;,&quot;maxdate&quot;:&quot;2021-07-02&quot;,&quot;name&quot;:&quot;Weather Radar (Level III)&quot;,&quot;datacoverage&quot;:0.95,&quot;id&quot;:&quot;NEXRAD3&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00821&quot;,&quot;mindate&quot;:&quot;2010-01-01&quot;,&quot;maxdate&quot;:&quot;2010-01-01&quot;,&quot;name&quot;:&quot;Normals Annual/Seasonal&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;NORMAL_ANN&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00823&quot;,&quot;mindate&quot;:&quot;2010-01-01&quot;,&quot;maxdate&quot;:&quot;2010-12-31&quot;,&quot;name&quot;:&quot;Normals Daily&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;NORMAL_DLY&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00824&quot;,&quot;mindate&quot;:&quot;2010-01-01&quot;,&quot;maxdate&quot;:&quot;2010-12-31&quot;,&quot;name&quot;:&quot;Normals Hourly&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;NORMAL_HLY&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00822&quot;,&quot;mindate&quot;:&quot;2010-01-01&quot;,&quot;maxdate&quot;:&quot;2010-12-01&quot;,&quot;name&quot;:&quot;Normals Monthly&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;NORMAL_MLY&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00505&quot;,&quot;mindate&quot;:&quot;1970-05-12&quot;,&quot;maxdate&quot;:&quot;2014-01-01&quot;,&quot;name&quot;:&quot;Precipitation 15 Minute&quot;,&quot;datacoverage&quot;:0.25,&quot;id&quot;:&quot;PRECIP_15&quot;},{&quot;uid&quot;:&quot;gov.noaa.ncdc:C00313&quot;,&quot;mindate&quot;:&quot;1900-01-01&quot;,&quot;maxdate&quot;:&quot;2014-01-01&quot;,&quot;name&quot;:&quot;Precipitation Hourly&quot;,&quot;datacoverage&quot;:1,&quot;id&quot;:&quot;PRECIP_HLY&quot;}]}
  </code></pre>
  <p>Code :</p>
  <pre><code>module Main where
  
  import Data.Aeson
  import qualified Data.Text as T
  import qualified Data.ByteString.Lazy as B
  import qualified Data.ByteString.Lazy.Char8 as BC
  import GHC.Generics
  import Control.Monad
  import Control.Applicative
  import System.IO
  </code></pre>
  <p>Data Type declaration for the data inside data.json :</p>
  <pre><code>    data NOAAResult = NOAAResult
                  { uid :: T.Text
                  , mindate :: T.Text
                  , maxdate :: T.Text
                  , name :: T.Text
                  , datacoverage :: Int
                  , resultId :: T.Text
                  } deriving Show
  
      instance FromJSON NOAAResult where
          parseJSON (Object v) =
                          NOAAResult &lt;$&gt; v .: &quot;uid&quot;
                              &lt;*&gt; v .: &quot;mindate&quot;
                              &lt;*&gt; v .: &quot;maxdate&quot;
                              &lt;*&gt; v .: &quot;name&quot;
                              &lt;*&gt; v .: &quot;datacoverage&quot;
                              &lt;*&gt; v .: &quot;id&quot;                  
  
      data Resultset = Resultset
                  { offset :: Int
                  , count :: Int
                  , limit :: Int
                  } deriving (Show,Generic)
                
      instance FromJSON Resultset
                
      data Metadata = Metadata
                  {
                  resultset :: Resultset
                  } deriving (Show,Generic)
                
      instance FromJSON Metadata
  
      data NOAAResponse = NOAAResponse
                  { metadata :: Metadata
                  , results :: [NOAAResult]
                  } deriving (Show,Generic)
                
      instance FromJSON NOAAResponse
  </code></pre>
  <p>IO actions :</p>
  <pre><code>    printResults :: Maybe [NOAAResult] -&gt; IO ()
      printResults Nothing = print &quot;error loading data&quot;
      printResults (Just results) = do
      forM_ results (print . name)
  
  
      main :: IO ()
      main = do
       jsonData &lt;- B.readFile &quot;data.json&quot;
       let noaaResponse = decode jsonData :: Maybe NOAAResponse
       let noaaResults = results &lt;$&gt; noaaResponse
       printResults noaaResults
  </code></pre>
  <ul>
  <li><p>Would be helpful to know the right place and right procedure to place input data file in haskell-stack.</p>
  </li>
  <li><p>Also, after placing the data file in the respective folder/path, what updates need to be made in config files (like cabal (or) package.yaml) and in the code (like import System.IO) - so that the haskell program would have no issue in identifying the input data file from the stack-project folder and process it fine. ( As in my case, it gives 'Error loading data' message - even when the data.json input file is placed inside stack-proj folder. Hence, I assume, I am missing something to do it right)</p>
  </li>
  </ul>
  <p>Requesting for guidance/help.</p>
  <p>Thank you.</p>